Hi,
I have two sorted sets, z1 and z2, with the same elements but different scores.
How would I compare the scores of set z1 with those of z2, and list only those with the highest scores of set z1 with respect to z2?
I can use only Redis commands
Thanks
kyle
2
This sounds like a class assignment!
I think want you want to do look at ZUNIONSTORE with the AGGREGATE MAX
argument.
suyog
3
@JRedis2020
See, if it helps:
redis> ZADD z1 100 player:1
(integer) 1
redis> ZADD z1 120 player:2
(integer) 1
redis> ZADD z1 90 player:3
(integer) 1
redis> ZADD z2 180 player:1
(integer) 1
redis> ZADD z2 160 player:3
(integer) 1
redis> ZADD z2 140 player:2
(integer) 1
redis> ZUNIONSTORE finalset 2 z1 z2
(integer) 3
redis> ZRANGE finalset 0 -1 WITHSCORES
1) "player:3" 2) "250" 3) "player:2" 4) "260" 5) "player:1" 6) "280"
redis> ZREVRANGE finalset 0 -1 WITHSCORES
1) "player:1" 2) "280" 3) "player:2" 4) "260" 5) "player:3" 6) "250"