SRANDMEMBER
and SPOP
always returns/removes only the lowest scoring element(s)
#3018
Labels
bug
Something isn't working
Describe the bug
SRANDMEMBER
should return random elements from the specified set, instead, it only returns the lowest scoring element(s).The
SPOP
command has the same problem, each time it removes only the lowest scoring element(s) from the set.To Reproduce
SRANDMEMBER
The steps to reproduce the behavior of the
SRANDMEMBER
command:redis-cli SADD myset one two three four five six seven eight nine ten
seq 20 | xargs -I {} redis-cli SRANDMEMBER myset
The result is always "eight".
SPOP
The steps to reproduce the
SPOP
behavior are more tricky. After each deletion of an element, we must return it back to the set in order to keep the same set of elements:Insert elements into a set:
redis-cli SADD myset one two three four five six seven eight nine ten
Remove the element and return it back multiple times:
for i in {1..20}; do redis-cli SPOP myset | tee -a removed_members.txt | xargs -I {} redis-cli SADD myset {}; done
SPOP
andSADD
, we write theSPOP
result to the fileremoved_members.txt
. As a result, inremoved_members.txt
we can see which elements were deleted during theSPOP
commands.In
removed_members.txt
we can see that "eight" was deleted each time.Expected behavior
It is expected that both commands return/remove a pseudo random element for each invocation.
SRANDMEMBER
SPOP
Environment (please complete the following information):
Reproducible Code Snippet
SRANDMEMBER
redis-cli SADD myset one two three four five six seven eight nine ten seq 20 | xargs -I {} redis-cli SRANDMEMBER myset
SPOP
Additional context
The problem is very similar to #2850.
The text was updated successfully, but these errors were encountered: