Skip to content

Conversation

shohamazon
Copy link
Collaborator

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.

@shohamazon shohamazon requested a review from a team as a code owner January 30, 2024 13:48
@Yury-Fridlyand Yury-Fridlyand added the python 🐍 Python wrapper label Jan 30, 2024
int: The number of members in the specified score range.

Examples:
>>> await zcount("my_sorted_set", BoundPair(5.0 , true) , InfBound.POS_INF)
Copy link
Collaborator

@barshaul barshaul Feb 1, 2024

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".
Copy link
Collaborator

@barshaul barshaul Feb 1, 2024

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?

Copy link
Collaborator

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?

Copy link
Collaborator Author

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:
Copy link
Collaborator

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.
Copy link
Collaborator

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.
Copy link
Collaborator

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
Copy link
Collaborator

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

Copy link
Collaborator Author

@shohamazon shohamazon Feb 1, 2024

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

@shohamazon shohamazon force-pushed the python/zcount branch 3 times, most recently from 8615842 to b3ac229 Compare February 1, 2024 14:36
@shohamazon shohamazon requested a review from barshaul February 1, 2024 16:22
@shohamazon shohamazon merged commit 63c62f1 into valkey-io:main Feb 5, 2024
@shohamazon shohamazon deleted the python/zcount branch February 5, 2024 12:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
python 🐍 Python wrapper
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants