ZUNIONSTORE
计算给定的一个或多个有序集的并集,其中给定 key 的数量必须以 numkeys 参数指定,并将该并集(结果集)储存到destination。
默认情况下,结果集中某个成员的分数值是所有给定集下该成员分数值之和。
ZUNIONSTORE和ZITERSTORE的唯一区别就是前者并集,后者取交集,其他完全相同,所以不再用代码示例
Command
$ redis-cli -h 127.0.0.1 -p 6379
127.0.0.1:6379> zadd z1 1 cat 2 dog
(integer) 2
127.0.0.1:6379> zadd z2 2 cat 3 goose
(integer) 2
127.0.0.1:6379> ZUNIONSTORE z3 2 z1 z2
(integer) 3
127.0.0.1:6379> zrange z3 0 -1 withscores
1) "dog"
2) "2"
3) "cat"
4) "3"
5) "goose"
6) "3"
127.0.0.1:6379> ZUNIONSTORE z4 2 z1 z2 WEIGHTS 4 3
(integer) 3
127.0.0.1:6379> zrange z4 0 -1 withscores
1) "dog"
2) "8"
3) "goose"
4) "9"
5) "cat"
6) "10"
127.0.0.1:6379> ZUNIONSTORE z5 2 z1 z2 AGGREGATE MIN
(integer) 3
127.0.0.1:6379> zrange z5 0 -1 withscores
1) "cat"
2) "1"
3) "dog"
4) "2"
5) "goose"
6) "3"
127.0.0.1:6379> ZUNIONSTORE z6 2 z1 z2 AGGREGATE MAX
(integer) 3
127.0.0.1:6379> zrange z6 0 -1 withscores
1) "cat"
2) "2"
3) "dog"
4) "2"
5) "goose"
6) "3"
127.0.0.1:6379> ZUNIONSTORE z7 2 z1 z2 WEIGHTS 4 3 AGGREGATE MAX
(integer) 3
127.0.0.1:6379> zrange z7 0 -1 withscores
1) "cat"
2) "6"
3) "dog"
4) "8"
5) "goose"
6) "9"