-
Notifications
You must be signed in to change notification settings - Fork 0
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
Python: add ZRANDMEMBER command #276
Conversation
There was a problem hiding this comment.
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!
// 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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If negative, allows for duplicates. | |
If `count` is negative, allows for duplicate elements. |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my comment above
bae7b4e
into
python/integ_acongo_zrandmember
* Python: add ZRANDMEMBER command (#276)
* Python: add ZRANDMEMBER command (#276)
No description provided.