Redis Srem Command | .com
Redis Tutorial
Redis Commands
Advanced Redis Tutorials
Redis Srem Command
The Redis SREM command is used to remove one or more members from a set. Members that do not exist in the set are ignored.
If the key is not of type set, an error will be returned.
In Redis versions prior to 2.4, SREM only accepted a single member value.
Syntax
The basic syntax for the Redis SREM command is as follows:
redis 127.0.0.1:6379> SREM KEY MEMBER1..MEMBERN
Available Version
>= 1.0.0
Return Value
The number of elements successfully removed, excluding those that were ignored.
Example
redis 127.0.0.1:6379> SADD myset1 "hello"
(integer) 1
redis 127.0.0.1:6379> SADD myset1 "world"
(integer) 1
redis 127.0.0.1:6379> SADD myset1 "bar"
(integer) 1
redis 127.0.0.1:6379> SREM myset1 "hello"
(integer) 1
redis 127.0.0.1:6379> SREM myset1 "foo"
(integer) 0
redis 127.0.0.1:6379> SMEMBERS myset1
1) "bar"
2) "world"
YouTip