directory search
Cluster cluster addslots(集群 槽位) cluster count failure reports(集群计数失败报告) cluster countkeysinslot cluster delslots cluster failover cluster forget cluster getkeysinslot cluster info cluster keyslot(集群键槽) cluster meet cluster nodes(集群节点) cluster replicate(集群复制) cluster reset(集群重置) cluster saveconfig cluster set config epoch cluster setslot cluster slaves cluster slots readonly readwrite Connection auth echo ping quit select swapdb Geo geoadd geodist geohash geopos georadius georadiusbymember Hashes hdel hexists hget hgetall hincrby hincrbyfloat hkeys hlen hmget hmset hscan hset hsetnx hstrlen hvals HyperLogLog pfadd pfcount pfmerge Keys del dump exists expire expireat keys migrate move object persist pexpire pexpireat pttl randomkey rename renamenx restore scan sort touch ttl type unlink wait Lists blpop brpop brpoplpush lindex linsert llen lpop lpush lpushx lrange lrem lset ltrim rpop rpoplpush rpush rpushx Pub/Sub psubscribe publish pubsub punsubscribe subscribe unsubscribe Scripting eval evalsha script debug script exists script flush script kill script load Server bgrewriteaof bgsave client getname client kill client list client pause client reply client setname command command count command getkeys command info config get config resetstat config rewrite config set dbsize debug object debug segfault flushall flushdb info lastsave monitor role save shutdown slaveof slowlog time Sets sadd scard sdiff sdiffstore sinter sinterstore sismember smembers smove spop srandmember srem sscan sunion sunionstore Sorted Sets zadd zcard zcount zincrby zinterstore zlexcount zrange zrangebylex zrangebyscore zrank zrem zremrangebylex zremrangebyrank zremrangebyscore zrevrange zrevrangebylex zrevrangebyscore zrevrank zscan zscore zunionstore Strings append bitcount bitfield bitop bitpos decr decrby get getbit getrange getset incr incrby incrbyfloat mget mset msetnx psetex set setbit setex setnx setrange strlen Transactions discard exec multi unwatch watch
characters

ZUNIONSTORE destination numkeys key [key ...] [WEIGHTS weight [weight ...]] [AGGREGATE SUM|MIN|MAX]

自2.0.0起可用。

时间复杂度: O(N)+ O(M log(M)),其中 N 是输入排序集合的大小之和,M 是结果排序集合中元素的数量。

计算numkeys指定键给出的有序集合的并集,并将结果存储在中destinationnumkeys在传递输入键和其他(可选)参数之前,必须提供输入键()的数量。

默认情况下,元素的结果得分是其存在的有序集合中的得分总和。

使用WEIGHTS选项,可以为每个输入排序集指定一个乘法因子。这意味着在传递给聚合函数之前,每个输入排序集合中的每个元素的分数都乘以该因子。当WEIGHTS没有给出时,乘法因子默认为1

使用AGGREGATE选项,可以指定如何汇总工会的结果。该选项默认为SUM,元素的分数在其存在的输入中求和。当此选项设置为MIN或时MAX,结果集将包含输入中存在的输入的最小或最大分数。

如果destination已经存在,它将被覆盖。

返回值

整数回复:在destination的排序集中的元素数。

例子

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"

Previous article: Next article: