ZUNION(3valkey)
β¨ ZUNION π (from the valkey command manual, bestie)
okay so we're doing zunion today and honestly? it's giving "math but make it cute". it's a Valkey command, it lives in section 3 of the manual, and it's about to be your new fave. π¦
πΈ NAME πΈ
zunion β returns the union of multiple sorted sets. that's it, that's the whole vibe. π
π«Ά SYNOPSIS π«Ά
ZUNION numkeys key [key...] [WEIGHTS weight [weight...]] [AGGREGATE
<SUM | MIN | MAX>] [WITHSCORES]
literally just hand it some keys and it does the thing, periodt. β¨
π DESCRIPTION π
bestie, listen. this command is basically ZUNIONSTORE's cooler sibling β same energy, but instead of writing the resulting sorted set somewhere and keeping it, it just returns it straight to the client. no storage, no commitment, just vibes. π
and for the whole rundown on the WEIGHTS and AGGREGATE options? yeah, go read ZUNIONSTORE, it's all explained over there. iykyk. π
π REPLY π
valkey-protocol(7) Array reply: the result of the union, and β if you threw WITHSCORES in there β their scores too. slay. π₯
π§ COMPLEXITY π§
O(N)+O(M*log(M))
where N is the sum of the sizes of all the input sorted sets, and M is the number of elements in the resulting sorted set. math is mathing, don't worry about it. β
π ACL CATEGORIES π
@read@slow@sortedset
π HISTORY π
- available since: 6.2.0 β she's been iconic for a minute. π
π EXAMPLES π
watch me cook:
127.0.0.1:6379> ZADD zset1 1 "one"
(integer) 1
127.0.0.1:6379> ZADD zset1 2 "two"
(integer) 1
127.0.0.1:6379> ZADD zset2 1 "one"
(integer) 1
127.0.0.1:6379> ZADD zset2 2 "two"
(integer) 1
127.0.0.1:6379> ZADD zset2 3 "three"
(integer) 1
127.0.0.1:6379> ZUNION 2 zset1 zset2
1) "one"
2) "three"
3) "two"
127.0.0.1:6379> ZUNION 2 zset1 zset2 WITHSCORES
1) "one"
2) "2"
3) "three"
4) "3"
5) "two"
6) "4"
see how "two" is lowkey carrying the score of 4? that's the union math doing its little dance. ate. π
π¦ SEE ALSO π¦
bzmpop(3valkey)bzpopmax(3valkey)bzpopmin(3valkey)zadd(3valkey)zcard(3valkey)zcount(3valkey)zdiff(3valkey)zdiffstore(3valkey)zincrby(3valkey)zinter(3valkey)zintercard(3valkey)zinterstore(3valkey)zlexcount(3valkey)zmpop(3valkey)zmscore(3valkey)zpopmax(3valkey)zpopmin(3valkey)zrandmember(3valkey)zrange(3valkey)zrangebylex(3valkey)zrangebyscore(3valkey)zrangestore(3valkey)zrank(3valkey)zrem(3valkey)zremrangebylex(3valkey)zremrangebyrank(3valkey)zremrangebyscore(3valkey)zrevrange(3valkey)zrevrangebylex(3valkey)zrevrangebyscore(3valkey)zrevrank(3valkey)zscan(3valkey)zscore(3valkey)zunionstore(3valkey)
and that's the whole page, bestie! go forth and union your little hearts out. π«Άβ¨
version 9.0.0, dated 2025-10-21, straight from the ZUNION(3valkey) manual page β mwah, xoxo, catch you in the next one ππ
πΈ
π¦ where this page comes from
- fedora 44: valkey-doc 9.0.3-2.fc44 Β· CC-BY-SA-4.0
- fedora 44: valkey-doc 9.0.6-1.fc44 Β· CC-BY-SA-4.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms