SREM command in redis

SREM key member

Remove the specified member from the set value stored at the key.

Note:

1. If a member was not a member of the set no operation is performed.

2. If the key does not hold a set value an error is returned.

TIME COMPLEXITY: O(1)

RETURN VALUE: Integer reply, specifically:

1 if the new element was removed

0 if the new element was not a member of the set.

Syntax:

SREM key member

Example 1: When the member is present

redis:6379> SADD redisKey 3 4 5 6 7 8
(integer) 6
redis:6379> SREM redisKey 4
(integer) 1

Output

1


Example 2: When the member is not present

redis:6379> SADD redisKey 3 4 5 6 7 8
(integer) 6
redis:6379> SREM redisKey 1
(integer) 0

Output

0


Example 3: When the key is not of set type.

redis:6379> SET myKey 199
"OK"
redis:6379> SREM myKey 199
(error) WRONGTYPE Operation against a key holding
the wrong kind of value

Output

(error) WRONGTYPE Operation against a key holding the wrong kind of value


No comments:

Post a Comment