Reputation: 79
I an using phpredis and i have something like below: $qrand = $redis->sRandMember('qall',25); Is there a simple way of storing the resulting array in a SET other than looping and adding to the set?
Upvotes: 1
Views: 91
Reputation: 50102
You can compose a Lua script that does that for you. Something like the following should work:
EVAL "redis.replicate_commands() redis.call('SADD',KEYS[2],unpack(redis.call('SRANDMEMBER', KEYS[1],ARGV[1]))" 2 qall tmp 25
Note: this works only with Redis v3.2 and above due to randomness.
Upvotes: 1