Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Redis Srem Command

Redis Srem Command

Redis Set

The Redis Srem command is used to remove one or more member elements from the set; non-existent member elements are ignored.

Returns an error when key is not of set type.

Before Redis 2.4, SREM only accepted a single member value.

Syntax

The basic syntax of 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 ignored elements.

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"

Redis Set