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

Python: add ZRANDMEMBER command #276

Merged

Conversation

aaron-congo
Copy link

No description provided.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, lack of RESP2 support in java client strikes again!

glide-core/src/client/value_conversion.rs Show resolved Hide resolved
glide-core/src/client/value_conversion.rs Outdated Show resolved Hide resolved
python/python/glide/async_commands/core.py Show resolved Hide resolved
python/python/glide/async_commands/core.py Outdated Show resolved Hide resolved
python/python/glide/async_commands/core.py Show resolved Hide resolved
python/python/tests/test_async_client.py Outdated Show resolved Hide resolved
glide-core/src/client/value_conversion.rs Outdated Show resolved Hide resolved
// The server response scores can be strings or doubles. The conversions we do here are as follows:
//
// - if the server returned nil, return nil
// - if the server returned an empty array, return an empty array

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this ever happen? I think the commands will return nil, and we won't ever get an empty array

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the redis docs: "Array reply: when the additional count argument is passed, the command returns an array of members, or an empty array when key doesn't exist."

Examples:
>>> await client.zrandmember("my_sorted_set")
"GLIDE" # "GLIDE" is a random member of "my_sorted_set".
>>> await client.zrandmember("non_existing_sorted_set")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we shouldn't include error cases - examples should demonstrate how to use the command, not how to not use it...

Copy link
Author

@aaron-congo aaron-congo May 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied this example from the Java client, which also includes this example of executing this command against a non-existing key. There are also other commands in core.py that include examples of executing against a non-existing key.

key (str): The key of the sorted set.
count (int): The number of elements to return.
If `count` is positive, returns unique elements.
If negative, allows for duplicates.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
If negative, allows for duplicates.
If `count` is negative, allows for duplicate elements.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll change this here and for hrandfield which has the same line. Note that the Java docs worded this the same so we may want to change it there as well

Examples:
>>> await client.zrandmember("my_sorted_set", -3)
["GLIDE", "GLIDE", "PYTHON"] # "GLIDE" and "PYTHON" are random members of "my_sorted_set".
>>> await client.zrandmember("non_existing_sorted_set", 3)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should remove this example

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment above

python/python/glide/async_commands/core.py Outdated Show resolved Hide resolved
@aaron-congo aaron-congo merged commit bae7b4e into python/integ_acongo_zrandmember May 14, 2024
43 checks passed
@aaron-congo aaron-congo deleted the python/dev_acongo_zrandmember branch May 14, 2024 21:39
aaron-congo added a commit that referenced this pull request May 16, 2024
aaron-congo added a commit that referenced this pull request May 16, 2024
* Python: add ZRANDMEMBER command (#276)
cyip10 pushed a commit that referenced this pull request Jun 24, 2024
* Python: add ZRANDMEMBER command (#276)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants