SADD(3valkey)
π SADD β the Valkey glow-up for your sets π
okay so welcome to SADD(3valkey), straight out of the Valkey Command Manual. Bestie, this is the command that adds one or more members to a set, and lowkey it creates the key if it doesn't exist like it's manifesting for you. β¨
πΈ NAME πΈ
sadd β adds one or more members to a set. Creates the key if it doesn't exist. π
π¦ SYNOPSIS π¦
SADD key member [member...]
π DESCRIPTION π
Add the specified members to the set stored at key. Members that are already in that set? They get ignored, bestie β no double-dipping, no duplicates, we don't do that here. π
If key does not exist, a brand new set is created before the specified members get added. It's giving main character debut. π
Heads up though: an error is returned when the value stored at key is not a set. So if you try to SADD onto, like, a string? It's not gonna work, and the server will call you out. π
π REPLY π
valkey-protocol(7) Integer reply: the number of elements that were actually added to the set β not counting all the elements that were already chillin' in there. So if nothing new landed, you get a 0 and that's just the vibe. β
β¨ COMPLEXITY β¨
O(1) for each element added, so O(N) to add N elements when the command is called with multiple arguments. Fr fr, it scales. π₯
π ACL CATEGORIES π
@fast @set @write
π«Ά HISTORY π«Ά
- Available since: 1.0.0
- Changed in 2.4.0: Accepts multiple member arguments. (iconic upgrade, we love to see it)
π EXAMPLES π
127.0.0.1:6379> SADD myset "Hello"
(integer) 1
127.0.0.1:6379> SADD myset "World"
(integer) 1
127.0.0.1:6379> SADD myset "World"
(integer) 0
127.0.0.1:6379> SMEMBERS myset
1) "Hello"
2) "World"
See how that third SADD came back with (integer) 0? That's the duplicate getting politely ignored. Set behaviour, periodt. π
π SEE ALSO π
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), sunion(3valkey), sunionstore(3valkey)
mwah π that's a wrap! This page is from Valkey 9.0.0, dated 2025-10-21. Go add some members, bestie, you're gonna slay. π¦πΈπ
π¦ 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