SUNION(3valkey)

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

✨ SUNION ✨

okay bestie, welcome to the Valkey Command Manual πŸ’– and yes this is sunion(3valkey) β€” the union glitch, the "everybody in the group chat gets added" energy πŸ‘‘


🌸 NAME 🌸

sunion β€” Returns the union of multiple sets. πŸ¦‹


πŸŽ€ SYNOPSIS πŸŽ€

SUNION key [key...]

πŸ’… DESCRIPTION πŸ’…

So basically, this one returns the members of the set that comes out of the union of all the sets you handed it. Every element from every set, deduped, one big happy family. 🌈

Like, for example:

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

notice how c is in literally all three and it only shows up once? that's the whole point, no dupes, we don't do dupes here πŸ’€

And keys that do not exist? They're considered to be empty sets. No drama, no error, just nothing contributed. 🫢


πŸ‘‘ 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. so it scales with everything you throw at it, keep that in mind 🧚


πŸ’œ ACL CATEGORIES πŸ’œ

@read @set @slow


πŸ¦‹ HISTORY πŸ¦‹

  • Available since: 1.0.0 β€” an actual og, been here since the beginning πŸ’…

✨ EXAMPLES ✨

okay let's actually see it in action:

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> SUNION key1 key2
1) "a"
2) "b"
3) "c"
4) "d"
5) "e"

see how c was in both key1 and key2 and still came out once? that's the union doing its little magic trick βœ¨πŸŽ€


🌈 SEE ALSO 🌈


and that's the whole page bestie 🫢 go union some sets, you're gonna eat πŸ’…βœ¨

this lil masterpiece is from Valkey version 9.0.0, dated 2025-10-21 β€” iconic, timeless, no cap πŸ‘‘πŸ’–

πŸ“¦ where this page comes from