sadd.3valkey - Man Page

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. Specified members that are already a member of this set are ignored. If key does not exist, a new set is created before adding the specified members.

An error is returned when the value stored at key is not a set.

Reply

valkey-protocol(7) Integer reply: the number of elements that were added to the set, not including all the elements already present in the set.

Complexity

O(1) for each element added, so O(N) to add N elements when the command is called with multiple arguments.

Acl Categories

@fast @set @write

History

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 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)

Info

2024-09-23 8.0.0 Valkey Command Manual