我試圖用Lua中搜索字段值在哈希,我做錯了什麼:) 我有鑰匙「文章」,這是zset控股文章ID和鍵文章:N其中「n」是商品編號。 下面的腳本:搜索在Redis的評估Lua中
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
返回此:
1) 1) "slug"
2) "first-title"
3) "title"
4) "first title"
2) 1) "slug"
2) "second-title"
3) "title"
4) "second title"
比我想包括條件,只返回在標題包含字符串「秒」鍵,但是它沒有返回。
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
請你能幫助我嗎?
不管該情況的問題,你應該注意到的是在腳本中使用的所有鍵名應通過使用'KEYS'參數表 - 動態訪問密鑰(例如基於Sorted Set範圍的內容)不能保證在羣集環境中工作。 –