srem.3valkey - Man Page

Removes one or more members from a set. Deletes the set if the last member was removed.

Synopsis

SREM key member [member...]

Description

Remove the specified members from the set stored at key. Specified members that are not a member of this set are ignored. If key does not exist, it is treated as an empty set and this command returns 0.

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

Reply

Resp2

valkey-protocol(7) Integer reply: the number of members that were removed from the set, not including non existing members.

Resp3

valkey-protocol(7) Integer reply: Number of members that were removed from the set, not including non existing members.

Complexity

O(N) where N is the number of members to be removed.

Acl Categories

@fast @set @write

History

Examples

127.0.0.1:6379> SADD myset "one"
(integer) 1
127.0.0.1:6379> SADD myset "two"
(integer) 1
127.0.0.1:6379> SADD myset "three"
(integer) 1
127.0.0.1:6379> SREM myset "one"
(integer) 1
127.0.0.1:6379> SREM myset "four"
(integer) 0
127.0.0.1:6379> SMEMBERS myset
1) "two"
2) "three"

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), sscan(3valkey), sunion(3valkey), sunionstore(3valkey)

Info

2024-09-23 8.0.0 Valkey Command Manual