Syntax
ZUNIONSTORE destination
numkeys key [key ...] [WEIGHTS weight [weight ...]] [AGGREGATE
SUM|MIN|MAX]
Computes the union of all
sorted sets and store the result into destination. Weight and
aggregate arguments are optional. If you don't specify weight and
aggregate arguments, then the resulting score of an element is the
sum of its scores in the sorted sets where it exists.
127.0.0.1:6379> zadd set1 2 India 1 America 3 Brazil (integer) 3 127.0.0.1:6379> zadd set2 3 China 4 India 2 Japan (integer) 3 127.0.0.1:6379> zadd set3 1 Italy 3 Nepal 2 America (integer) 3 127.0.0.1:6379> zunionstore set4 3 set1 set2 set3 (integer) 7 127.0.0.1:6379> zrange set4 0 6 withscores 1) "Italy" 2) "1" 3) "Japan" 4) "2" 5) "America" 6) "3" 7) "Brazil" 8) "3" 9) "China" 10) "3" 11) "Nepal" 12) "3" 13) "India" 14) "6" 127.0.0.1:6379>
WEIGHTS option is used to
specify a multiplication factor for each input sorted set, The score
of every element in every input sorted set is multiplied by this
factor before being passed to the aggregation function. If you don't
specify any WEIGHTS option, multiplication option is set to 1.
127.0.0.1:6379> zunionstore set5 3 set1 set2 set3 weights 1 2 3
(integer) 7
127.0.0.1:6379> zrange set5 0 6 withscores
1) "Brazil"
2) "3"
3) "Italy"
4) "3"
5) "Japan"
6) "4"
7) "China"
8) "6"
9) "America"
10) "7"
11) "Nepal"
12) "9"
13) "India"
14) "10"
AGGREGATE argument defaults to
SUM, where the score of an element is summed across the inputs where
it exists.
If AGGREGATE argument set to
MIN, then the resulting set will contain the minimum score of an
element across the input sorted sets where it exists.
If AGGREGATE argument set to
MAX, then the resulting set will contain the maximum score of an
element across the input sorted sets where it exists.
127.0.0.1:6379> zunionstore set6 3 set1 set2 set3 weights 1 2 3 aggregate min (integer) 7 127.0.0.1:6379> zrange set6 0 6 withscores 1) "America" 2) "1" 3) "India" 4) "2" 5) "Brazil" 6) "3" 7) "Italy" 8) "3" 9) "Japan" 10) "4" 11) "China" 12) "6" 13) "Nepal" 14) "9"
127.0.0.1:6379> zunionstore set7 3 set1 set2 set3 weights 1 2 3 aggregate max (integer) 7 127.0.0.1:6379> zrange set7 0 6 withscores 1) "Brazil" 2) "3" 3) "Italy" 4) "3" 5) "Japan" 6) "4" 7) "America" 8) "6" 9) "China" 10) "6" 11) "India" 12) "8" 13) "Nepal" 14) "9"
No comments:
Post a Comment