Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SRANDMEMBER and SPOP always returns/removes only the lowest scoring element(s) #3018

Closed
BagritsevichStepan opened this issue May 6, 2024 · 0 comments · Fixed by #3022
Closed
Labels
bug Something isn't working

Comments

@BagritsevichStepan
Copy link
Contributor

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:

  1. Inserting elements into a set: redis-cli SADD myset one two three four five six seven eight nine ten
  2. Сalling SRANDMEMBER multiple times: 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:

  1. Insert elements into a set: redis-cli SADD myset one two three four five six seven eight nine ten

  2. 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

    • Notice: between running SPOP and SADD, we write the SPOP result to the file removed_members.txt. As a result, in removed_members.txt we can see which elements were deleted during the SPOP 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

$ seq 20 | xargs -I {} redis-cli SRANDMEMBER x 1
1) two
1) six
1) two
1) two
1) nine
1) three
1) five
1) two
1) ten
1) ten
1) nine
1) four
1) eight
1) two
1) five
1) three
1) five
1) four
1) nine
1) ten

SPOP

$ cat removed_members.txt
ten
nine
four
five
eight
eight
one
nine
two
nine
three
five
four
nine
eight
five
four
two
six
two

Environment (please complete the following information):

  • OS: ubuntu 20.04
  • Containerized: Docker
  • Dragonfly Version: v1.17.0

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

redis-cli SADD myset one two three four five six seven eight nine ten
for i in {1..30}; do redis-cli SPOP myset | tee -a removed_members.txt | xargs -I {} redis-cli SADD myset {}; done
cat removed_members.txt

Additional context

The problem is very similar to #2850.

@BagritsevichStepan BagritsevichStepan added the bug Something isn't working label May 6, 2024
BagritsevichStepan pushed a commit to BagritsevichStepan/dragonfly that referenced this issue May 7, 2024
fixes dragonflydb#3018

Signed-off-by: Stepan Bagritsevich <sbagritsevich@quantumbrains.com>
BagritsevichStepan pushed a commit to BagritsevichStepan/dragonfly that referenced this issue May 8, 2024
fixes dragonflydb#3018

Signed-off-by: Stepan Bagritsevich <sbagritsevich@quantumbrains.com>
BagritsevichStepan pushed a commit to BagritsevichStepan/dragonfly that referenced this issue May 8, 2024
fixes dragonflydb#3018

Signed-off-by: Stepan Bagritsevich <sbagritsevich@quantumbrains.com>
BagritsevichStepan pushed a commit to BagritsevichStepan/dragonfly that referenced this issue May 9, 2024
fixes dragonflydb#3018

Signed-off-by: Stepan Bagritsevich <sbagritsevich@quantumbrains.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant