Redis - Set Spop Command


Advertisements

Redis SPOP command is used to remove and return a random member from the set stored at a specified key.

Return Value

String reply, the removed element, or nil when the key does not exist.

Syntax

Following is the basic syntax of Redis SPOP command.

redis 127.0.0.1:6379> SPOP KEY

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> SPOP myset1 
"bar" 
redis 127.0.0.1:6379> SMEMBERS myset1 
1) "Hello" 
2) "world" 
redis_sets.htm
Advertisements