ZDIFF(3valkey)

πŸ“¦
version 9.0.6 Β· 2 versions
, in fedora 44

πŸ’– 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 the WITHSCORES option 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:


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