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 BZPOPMIN and BZPOPMAX commands #1399

Merged
merged 4 commits into from
May 14, 2024

Conversation

aaron-congo
Copy link
Collaborator

Issue #, if available:
N/A

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.

@@ -21,6 +21,7 @@ pub(crate) enum ExpectedReturnType {
Lolwut,
ArrayOfArraysOfDoubleOrNull,
ArrayOfKeyValuePairs,
KeyWithMemberAndScore,
Copy link
Collaborator

Choose a reason for hiding this comment

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

How come this wasn't included in the Java implementation?

Copy link
Collaborator

Choose a reason for hiding this comment

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

ig it was forgotten, good catch:)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah its because the conversion is needed for RESP2 responses. The Java wrapper doesn't support RESP2 yet but Python does

if array.len() == 3
&& matches!(array[2], Value::BulkString(_) | Value::SimpleString(_)) =>
{
array[2] =
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this only convert the third argument to double? Can there be more arguments with more keys where the timeout is greater than the third argument?

Copy link
Collaborator

Choose a reason for hiding this comment

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

redis> ZADD zset1 0 a 1 b 2 c
(integer) 3
redis> BZPOPMIN zset1 zset2 0
1) "zset1"
2) "a"
3) "0"

replay can be one of the following:

Nil reply: when no element could be popped and the timeout expired.
Array reply: the keyname, popped member, and its score.

so when its an array replay, which means we popped an element, we want to convert just the score from string to double

Copy link
Collaborator

Choose a reason for hiding this comment

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

Gotcha, thanks!

Copy link
Collaborator

Choose a reason for hiding this comment

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

np

@@ -21,6 +21,7 @@ pub(crate) enum ExpectedReturnType {
Lolwut,
ArrayOfArraysOfDoubleOrNull,
ArrayOfKeyValuePairs,
KeyWithMemberAndScore,
Copy link
Collaborator

Choose a reason for hiding this comment

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

ig it was forgotten, good catch:)

if array.len() == 3
&& matches!(array[2], Value::BulkString(_) | Value::SimpleString(_)) =>
{
array[2] =
Copy link
Collaborator

Choose a reason for hiding this comment

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

redis> ZADD zset1 0 a 1 b 2 c
(integer) 3
redis> BZPOPMIN zset1 zset2 0
1) "zset1"
2) "a"
3) "0"

replay can be one of the following:

Nil reply: when no element could be popped and the timeout expired.
Array reply: the keyname, popped member, and its score.

so when its an array replay, which means we popped an element, we want to convert just the score from string to double

Comment on lines 2305 to 2307
BZPOPMAX is the blocking variant of ZPOPMAX.

BZPOPMAX is a client blocking command, see https://github.com/aws/glide-for-redis/wiki/General-Concepts#blocking-commands for more details and best practices.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
BZPOPMAX is the blocking variant of ZPOPMAX.
BZPOPMAX is a client blocking command, see https://github.com/aws/glide-for-redis/wiki/General-Concepts#blocking-commands for more details and best practices.
`BZPOPMAX` is the blocking variant of `ZPOPMAX`.
`BZPOPMAX` is a client blocking command, see https://github.com/aws/glide-for-redis/wiki/General-Concepts#blocking-commands for more details and best practices.

Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe we should do:

BBZPOPMAX is a client blocking command, see [Blocking commands](https://github.com/aws/glide-for-redis/wiki/General-Concepts#blocking-commands) for more details and best practices.

image

Copy link
Collaborator Author

@aaron-congo aaron-congo May 13, 2024

Choose a reason for hiding this comment

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

I don't think hyperlinks like these are supported by default, according to this stack overflow post they aren't, but some tools and/or documentation generators may support them. Looks like VScode does, but I'm using pycharm and it doesn't. Let me know if you still want me to change this to a hyperlink though

image

python/python/glide/async_commands/core.py Outdated Show resolved Hide resolved
python/python/glide/async_commands/core.py Outdated Show resolved Hide resolved
python/python/glide/async_commands/core.py Outdated Show resolved Hide resolved
python/python/tests/test_async_client.py Show resolved Hide resolved
python/python/tests/test_async_client.py Show resolved Hide resolved
@aaron-congo aaron-congo force-pushed the python/integ_acongo_bzpopmax branch from a67c7ba to 3f1e3c4 Compare May 13, 2024 21:12
@aaron-congo
Copy link
Collaborator Author

@shohamazon Thanks for the review, all comments are addressed now

@Yury-Fridlyand
Copy link
Collaborator

@aaron-congo please, resolve conflicts and merge

@aaron-congo aaron-congo force-pushed the python/integ_acongo_bzpopmax branch from 9c3e15f to 6a23610 Compare May 13, 2024 23:54
@acarbonetto acarbonetto merged commit 8c590a7 into valkey-io:main May 14, 2024
45 checks passed
@acarbonetto acarbonetto deleted the python/integ_acongo_bzpopmax branch May 14, 2024 05:25
avifenesh pushed a commit that referenced this pull request May 14, 2024
* Python: add BZPOPMIN and BZPOPMAX commands (#266)

* Update PR link

* PR suggestions

* Fix rust
cyip10 pushed a commit to Bit-Quill/valkey-glide that referenced this pull request Jun 24, 2024
* Python: add BZPOPMIN and BZPOPMAX commands (#266)

* Update PR link

* PR suggestions

* Fix rust
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants