需要在redis中为多个键获取相同的字段。
127.0.0.1:6379> HGET Object:100:RATE:9008 properties.status
"OK"
127.0.0.1:6379> HGET Object:100:RATE:9000 properties.status
"NOT OK"
// PLANNING to have something like below
HGETMULTIPLE Object:100:RATE:9000 properties.status Object:100:RATE:9008 properties.status
"OK" "NOT OK"
需要在lua中执行此操作,因此lua解决方案也可以。但我知道卢安没有这样的流水线。
答案 0 :(得分:2)
是的,您可以使用Lua脚本来完成工作(它与流水线无关,而是脚本以原子方式运行):
-- HGETMULTIPLE.lua
local field = ARGV[1]
local res = {}
for i, key in ipairs(KEYS) do
res[#res+1] = redis.call("HGET", key, field)
end
return res
redis-cli --eval HGETMULTIPLE.lua Object:100:RATE:9008 Object:100:RATE:9000 , properties.status