Easy Tutorial
❮ Scripting Script Load Scripting Script Exists ❯

Redis Zunionstore Command

Redis Sorted Set

The Redis Zunionstore command calculates the union of one or more sorted sets given by the keys, where the number of keys must be specified by the numkeys parameter, and stores the union (result set) in the destination.

By default, the score of a member in the result set is the sum of its scores in the given sets.

Syntax

The basic syntax of the redis Zunionstore command 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

The number of members in the result set stored in the destination.

Example

redis> ZADD zset1 1 "one"
(integer) 1
redis> ZADD zset1 2 "two"
(integer) 1
redis> ZADD zset2 1 "one"
(integer) 1
redis> ZADD zset2 2 "two"
(integer) 1
redis> ZADD zset2 3 "three"
(integer) 1
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

❮ Scripting Script Load Scripting Script Exists ❯