ZDIFF(3valkey)
π ZDIFF π (like, the valkey command manual one, bestie)
okay so this is zdiff(3valkey) from the Valkey Command Manual and it's genuinely one of my faves, no cap. let's get into it π«Ά
β¨ NAME β¨
zdiff β returns the difference between multiple sorted sets. it's giving "what do these have that those don't" π
πΈ SYNOPSIS πΈ
ZDIFF numkeys key [key...] [WITHSCORES]
π¦ DESCRIPTION π¦
okay so real talk: this command is similar to ZDIFFSTORE, but here's the plot twist β instead of storing the resulting sorted set somewhere, it just hands it right back to the client. like, no storage era, just vibes β¨
π REPLY π
valkey-protocol(7)Array reply: the result of the difference, including, optionally, scores when theWITHSCORESoption is used.
π COMPLEXITY π
O(L + (N-K)log(N)) worst case β where L is the total number of elements in all the sets, N is the size of the first set, and K is the size of the result set. math girlies rise, we love a formula π
π ACL CATEGORIES π
@read @slow @sortedset
β HISTORY β
- Available since:
6.2.0
π 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 zset1 3 "three"
(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> ZDIFF 2 zset1 zset2
1) "three"
127.0.0.1:6379> ZDIFF 2 zset1 zset2 WITHSCORES
1) "three"
2) "3"
see how "three" is the only one left standing? main character energy fr fr π₯
π SEE ALSO π
the whole friend group, gathered:
bzmpop(3valkey)bzpopmax(3valkey)bzpopmin(3valkey)zadd(3valkey)zcard(3valkey)zcount(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)zunion(3valkey)zunionstore(3valkey)
ok that's the whole page bestie, every single option and reference accounted for, nothing skipped, we ate and left no crumbs π β¨
and that's a wrap! this lil beauty is version 9.0.0, dated 2025-10-21 π thanks for reading my ted talk, go forth and diff those sorted sets, mwah ππ¦
π¦ 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