SPOP command in redis

SPOP key

Remove a random element from a Set returning it as a return value. If the Set is empty or the key does not exist, a nil object is returned.

TIME COMPLEXITY: O(1)

RETURN VALUE: Bulk reply

Syntax:

SPOP key

Example 1: When the key is present

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

Output

1


Example 2: When the key is not present

redis:6379> SPOP redisKey
(nil)

Output

nil


No comments:

Post a Comment