Latest web development tutorials

Redis Zunionstore command

Redis ordered set (sorted set)

Redis Zunionstore command calculation given one or more ordered sets and set in which a given number of key parameters must be specified to numkeys, and the union (the result set) stored in the destination.

By default, the result set point value is a member of all the member under a given set of values ​​and scores.

grammar

redis Zunionstore basic command syntax is as follows:

redis 127.0.0.1:6379> ZUNIONSTORE destination numkeys key [key ...] [WEIGHTS weight [weight ...]] [AGGREGATE SUM|MIN|MAX]

Available versions

> = 2.0.0

return value

Save to the number of members of the destination of the result set.

Examples

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"

Redis ordered set (sorted set)