index = 1
while index <= string.len(data) do
index = string.find(data, "[^\0]", index)
if index != -1 then
# do something with this location
end
index = index + 1
end
That should repeatedly find non-nulls in the string, though my Lua is rusty.
Regards,
- Josiah
On Wed, Aug 22, 2012 at 6:48 PM, K <
ka...@viki.com> wrote:
> After doing a bitop, I'll looking to get the index of all set members. My
> initial approach was to GETRANGE(key, 0, -1) and let the client loop through
> the result looking for set bits (in node). I decided to try doing the filter
> in LUA and thus only returning set index. I was surprised that doing it
> server side was slower. I *think* part of the problem is that GETRANGE's
> response is treated as a string (whereas with node I can manipulate the
> buffer directly). This is the code I have:
>
> local ids = {}
> local data = redis.call('getrange', key, 0, -1)
> for i = 1, #data do
> if data:sub(i,i) == "\u0001" then
> table.insert(ids, i)
> end
> end
> return ids
>
>
> I realize this can be optimized by checking a subset with and skipping where
> BITCOUNT = 0...but I'm still curious if there's a faster way to do this in
> LUA?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Redis DB" group.
> To view this discussion on the web visit
>
https://groups.google.com/d/msg/redis-db/-/8c_rl_uSlxwJ.
> To post to this group, send email to
redi...@googlegroups.com.
> To unsubscribe from this group, send email to
>
redis-db+u...@googlegroups.com.
> For more options, visit this group at
>
http://groups.google.com/group/redis-db?hl=en.