The Redis SREM command removes one or more members from a set. Non-existent members are ignored.

An error is returned if the key is not of set type.

Syntax

The basic syntax of the SREM command is as follows:

1
SREM key member [member ...]

In Redis version 2.4 and earlier, SREM only accepted a single member value.

Available Since

Redis version >= 1.0.0

Time Complexity

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

ACL Categories

@write, @set, @fast

Return Value

Returns the number of members that were removed from the set, not including non existing members.

Example

1
2
3
4
5
6
7
8
9
10
11
127.0.0.1:6379> SADD myset a b c d e
(integer) 5
127.0.0.1:6379> SREM myset b
(integer) 1
127.0.0.1:6379> SREM myset f
(integer) 0
127.0.0.1:6379> SMEMBERS myset
1) "d"
2) "c"
3) "e"
4) "a"