Redis Spop Command
The Redis Spop command is used to remove one or more random elements from the set at the specified key; the removed elements are returned after removal.
This command is similar to Srandmember command, but SPOP removes the random element from the set and returns it, while Srandmember only returns the random element without making any changes to the set.
Syntax
The basic syntax of the redis Spop command is as follows:
SPOP key [count]
The count parameter is available in version 3.2+.
Available Version
= 1.0.0
Return Value
The removed random element. Returns nil when the set does not exist or is empty.
Example
redis> SADD myset "one"
(integer) 1
redis> SADD myset "two"
(integer) 1
redis> SADD myset "three"
(integer) 1
redis> SPOP myset
"one"
redis> SMEMBERS myset
1) "three"
2) "two"
redis> SADD myset "four"
(integer) 1
redis> SADD myset "five"
(integer) 1
redis> SPOP myset 3
1) "five"
2) "four"
3) "two"
redis> SMEMBERS myset
1) "three"
redis>
Redis Set