SPOP
Removes and returns one or more random members from the set value store at .
This operation is similar to SRANDMEMBER
, that returns one or more random elements from a set but does not remove it.
When called without the count
argument:
Bulk string reply: the removed member, or nil
when key
does not exist.
: the removed members, or an empty array when key
does not exist.
dragonfly> SADD myset "one"
dragonfly> SADD myset "two"
(integer) 1
dragonfly> SADD myset "three"
dragonfly> SPOP myset
"one"
dragonfly> SMEMBERS myset
1) "three"
2) "two"
(integer) 1
dragonfly> SADD myset "five"
(integer) 1
1) "three"
2) "two"
3) "four"
dragonfly> SMEMBERS myset
1) "five"
Note that this command is not suitable when you need a guaranteed uniform distribution of the returned elements. For more information about the algorithms used for , look up both the Knuth sampling and Floyd sampling algorithms.