문제

i am new in redis . I want to know how to get multiple field's value from multiple sets in redis. is it possible in Redis . and if possible then how. Example

HSET myhash1 field1 "Hello"
HSET myhash2 field2 "Hello"
HSET myhash3 field3 "Hello"
    I want to get all the three field's value from different sets at a time?
도움이 되었습니까?

해결책

You can use Lua Scripting for this.

Example:

local a={}
a[1] = redis.call('hget',KEYS[1], KEYS[2])
a[2] = redis.call('hget',KEYS[3], KEYS[4])
a[3] = redis.call('hget',KEYS[5], KEYS[6])
return a

Coded for simplicity, ofcourse you'd make the parameters more flexible. You can also use cjson for input as well as output (if you keep in mind that serialisation eats up a tiny bit of CPU).

Another way is using pipelining, but I guess your question is about doing this atomically.

Hope this helps, TW

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top