SADD(3valkey)

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

πŸ’– 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