What's new in Valkey 9.0? Discover new features and improvements. Read the announcement.

SREM

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

Usage
SREM key member ...
Complexity
O(N) where N is the number of members to be removed.
Since
1.0.0
ACL Categories
@fast, @set, @write
Command flags
WRITE, FAST

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.

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"

Replies

RESP2

Integer reply: the number of members that were removed from the set, not including non existing members.

RESP3

Integer reply: the number of members that were removed from the set, not including non existing members.

History

  • 2.4.0: Accepts multiple `member` arguments.