SDIFF(3valkey)

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

πŸ’– SDIFF πŸ’–

okay bestie, welcome to the Valkey Command Manual entry for sdiff, and no, it's not "ess-diff" like some random file thing, it's set difference and it's iconic ✨


✨ NAME ✨

sdiff β€” Returns the difference of multiple sets.

πŸŽ€ SYNOPSIS πŸŽ€

SDIFF key [key...]

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so picture this: you've got a bunch of sets, and you want the members that are in the first set but not in any of the ones after it. That's literally it. That's the whole vibe.

Returns the members of the set resulting from the difference between the first set and all the successive sets.

For example:

key1 = {a,b,c,d}
key2 = {c}
key3 = {a,c,e}
SDIFF key1 key2 key3 = {b,d}

and here's the lil detail that saves you every single time: Keys that do not exist are considered to be empty sets. so no drama, no errors, just vibes 🫢

🌸 REPLY 🌸

RESP2

valkey-protocol(7) Array reply: a list with members of the resulting set.

RESP3

valkey-protocol(7) Set reply: the resulting set.

⭐ COMPLEXITY ⭐

O(N) where N is the total number of elements in all given sets.

ngl bestie, it scales with every single element in every set you hand it, not just the first one. keep that in mind before you yeet 40 giant sets at it πŸ’€

πŸ”₯ ACL CATEGORIES πŸ”₯

@read @set @slow

πŸ’… HISTORY πŸ’…

  • Available since: 1.0.0

she's been here since the beginning, a true main character πŸ‘‘

🌈 EXAMPLES 🌈

127.0.0.1:6379> SADD key1 "a"
(integer) 1
127.0.0.1:6379> SADD key1 "b"
(integer) 1
127.0.0.1:6379> SADD key1 "c"
(integer) 1
127.0.0.1:6379> SADD key2 "c"
(integer) 1
127.0.0.1:6379> SADD key2 "d"
(integer) 1
127.0.0.1:6379> SADD key2 "e"
(integer) 1
127.0.0.1:6379> SDIFF key1 key2
1) "a"
2) "b"

see how "c" ghosted? πŸ‘» it was in key1 AND key2, so SDIFF said "not on my watch" and left it out. "a" and "b" are the only ones with main character energy in key1 alone. periodt πŸ’–

🧚 SEE ALSO 🧚

sadd(3valkey), scard(3valkey), sdiffstore(3valkey), sinter(3valkey), sintercard(3valkey), sinterstore(3valkey), sismember(3valkey), smembers(3valkey), smismember(3valkey), smove(3valkey), spop(3valkey), srandmember(3valkey), srem(3valkey), sscan(3valkey), sunion(3valkey), sunionstore(3valkey)


okay that's the whole page bestie, you're officially a set-difference girly now πŸŽ€ this was Valkey 9.0.0, dated 2025-10-21 β€” go forth and SDIFF responsibly, mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from