Redis 有序集合(sorted set)
Redis Zunionstore 指令計算給定的一個或多個有序集的并集,其中給定 key 的數量必須以 numkeys 參數指定,并将該并集(結果集)儲存到 destination 。
預設情況下,結果集中某個成員的分數值是所有給定集下該成員分數值之和 。
文法
redis Zunionstore 指令基本文法如下:
redis 127.0.0.1:6379> ZUNIONSTORE destination numkeys key [key ...] [WEIGHTS weight [weight ...]] [AGGREGATE SUM|MIN|MAX]
可用版本
>= 2.0.0
傳回值
儲存到 destination 的結果集的成員數量。
執行個體
redis> ZADD zset1 1 "one"
(integer) 1
redis> ZADD zset1 2 "two"
redis> ZADD zset2 1 "one"
redis> ZADD zset2 2 "two"
redis> ZADD zset2 3 "three"
redis> ZUNIONSTORE out 2 zset1 zset2 WEIGHTS 2 3
(integer) 3
redis> ZRANGE out 0 -1 WITHSCORES
1) "one"
2) "5"
3) "three"
4) "9"
5) "two"
6) "10"
redis>
Redis 有序集合(sorted set)