Redis通过Lua一次获取多个key值

1.获取多个key值

local result ={} 
for i = 1,#(KEYS) do 
   result[i]= redis.call('get',KEYS[i]) 
end 
return result

redis-cli示例:

eval  "local result={}  for i = 1,#(KEYS) do result[i]= redis.call('get',KEYS[i]) end return result" 1 a

2.获取多个hash值

local result ={} 
local temp 
for i = 1,#(KEYS) do 
  temp= redis.call('hgetall', KEYS[i]) 
  result[i]=table.concat(temp,' ') 
end 
return result

redis-cli示例:

eval  "local result ={} local temp for i = 1,#(KEYS) do temp = redis.call('hgetall', KEYS[i]) result[i]=table.concat(temp,' ') end return result" 1 a

参考:http://redisdoc.com/script/eval.html

 

posted @ 2016-01-20 20:48  2GyAn  阅读(11976)  评论(1编辑  收藏  举报