I'm trying to search for field value in hash using Lua script and I'm doing something wrong :) I have key "articles" which is zset holding article IDs and keys article:n where "n" is the article number. The following script:
local ids = redis.call("zrange", 'articles', '0', '-1')
local ret = {}
for k, id in pairs(ids) do
local row = redis.call("hgetall", "article:"..id)
ret[k] = row
end
return ret
returns this:
1) 1) "slug"
2) "first-title"
3) "title"
4) "first title"
2) 1) "slug"
2) "second-title"
3) "title"
4) "second title"
Than I'm trying to include condition to return only keys containing string "second" in title but it returns nothing.
local ids = redis.call("zrange", 'articles', '0', '-1')
local ret = {}
for k, id in pairs(ids) do
local row = redis.call("hgetall", "article:"..id)
if (string.find(row[4], "second")) then
ret[k] = row
end
end
return ret
Please could you help me?
KEYSargument table - dynamically accessing keys (e.g. based on the contents of a Sorted Set range) is not ensured to work in a clustered environment. - Itamar Haber