Redis Zunionstore 命令
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 127.0.0.1:6379> ZRANGE programmer 0 -1 WITHSCORES 1) "peter" 2) "2000" 3) "jack" 4) "3500" 5) "tom" 6) "5000" redis 127.0.0.1:6379> ZRANGE manager 0 -1 WITHSCORES 1) "herry" 2) "2000" 3) "mary" 4) "3500" 5) "bob" 6) "4000" redis 127.0.0.1:6379> ZUNIONSTORE salary 2 programmer manager WEIGHTS 1 3 # 公司決定加薪。。。除了程式員。。。 (integer) 6 redis 127.0.0.1:6379> ZRANGE salary 0 -1 WITHSCORES 1) "peter" 2) "2000" 3) "jack" 4) "3500" 5) "tom" 6) "5000" 7) "herry" 8) "6000" 9) "mary" 10) "10500" 11) "bob" 12) "12000"