SUNION(3valkey)
β¨ 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 π
sadd(3valkey)scard(3valkey)sdiff(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)sunionstore(3valkey)
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
- 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