-
Notifications
You must be signed in to change notification settings - Fork 36
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: adds ZCOUNT command #878
Conversation
int: The number of members in the specified score range. | ||
|
||
Examples: | ||
>>> await zcount("my_sorted_set", BoundPair(5.0 , true) , InfBound.POS_INF) |
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.
please add the arg names to the BoundPair example to make it more readable, e.g.:
ScoreLimit(5.0 , is_inclusive=true)
>>> await zcount("my_sorted_set", BoundPair(5.0 , true) , InfBound.POS_INF) | ||
2 # Indicates that there are 2 members with scores between 5.0 (not exclusive) and +inf in the sorted set "my_sorted_set". | ||
>>> await zcount("my_sorted_set", BoundPair(5.0 , true) , BoundPair(1.0 , false)) | ||
1 # Indicates that there is one member with 5.0 < score <= 10.0 in the sorted set "my_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.
in the example you wrote 1.0, in the comment 10.0.
I guess that it's a typo, but what happens if max_score < min_score?
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.
what happens if key isn't exists? an error returned, or a null?
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 key
does not exist, it is treated as an empty sorted set, and the command returns 0.
If max_score
< min_score
, 0 is returned.
Added this to the doc.
NEG_INF = "-inf" | ||
|
||
|
||
class BoundPair: |
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.
BoundPair -> maybe ScoreLimit
|
||
Args: | ||
value (float): The score value. | ||
is_inclusive (bool): Whether the score is inclusive. Defaults to False. |
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.
Whether the score is inclusive. => Whether the score value is inclusive.
|
||
class BoundPair: | ||
""" | ||
Represents a pair of score and inclusivity in a 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.
Represents a score limit in a sorted set.
await redis_client.zcount(key, BoundPair(1, False), BoundPair(3, True)) == 2 | ||
) | ||
assert await redis_client.zcount(key, InfBound.NEG_INF, BoundPair(3, True)) == 3 | ||
assert await redis_client.zcount(key, InfBound.POS_INF, BoundPair(3, True)) == 0 |
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.
please add tests for non existing key and max < min
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.
this test exists (max < min), see:
assert await redis_client.zcount(key, InfBound.POS_INF, BoundPair(3, True)) == 0
8615842
to
b3ac229
Compare
b3ac229
to
c54a120
Compare
Issue #, if available:
Description of changes:
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.