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: added LMOVE and BLMOVE commands #1536

Merged
merged 5 commits into from
Jun 9, 2024

Conversation

GilboaAWS
Copy link
Collaborator

No description provided.

@GilboaAWS GilboaAWS requested a review from a team as a code owner June 6, 2024 12:22
@GilboaAWS GilboaAWS added the python Python wrapper label Jun 6, 2024
Comment on lines 1525 to 1526
>>> result = await client.lmove("testKey1", "testKey2", ListDirection.LEFT, ListDirection.LEFT)
>>> assert result == "one"
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
>>> result = await client.lmove("testKey1", "testKey2", ListDirection.LEFT, ListDirection.LEFT)
>>> assert result == "one"
>>> await client.lmove("testKey1", "testKey2", ListDirection.LEFT, ListDirection.LEFT)
"one"

Comment on lines 1527 to 1530
>>> updated_array1 = await client.lrange("testKey1", 0, -1)
>>> updated_array2 = await client.lrange("testKey2", 0, -1)
>>> assert updated_array1 == ["two"]
>>> assert updated_array2 == ["one", "three", "four"]
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
>>> updated_array1 = await client.lrange("testKey1", 0, -1)
>>> updated_array2 = await client.lrange("testKey2", 0, -1)
>>> assert updated_array1 == ["two"]
>>> assert updated_array2 == ["one", "three", "four"]
>>> await client.lrange("testKey1", 0, -1)
["two"]
>>> await client.lrange("testKey2", 0, -1)
["one", "three", "four"]

Comment on lines 1572 to 1577
>>> result = await client.blmove("testKey1", "testKey2", ListDirection.LEFT, ListDirection.LEFT, 0.1)
>>> assert result == "one"
>>> updated_array1 = await client.lrange("testKey1", 0, -1)
>>> updated_array2 = await client.lrange("testKey2", 0, -1)
>>> assert updated_array1 == ["two"]
>>> assert updated_array2 == ["one", "three", "four"]
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
>>> result = await client.blmove("testKey1", "testKey2", ListDirection.LEFT, ListDirection.LEFT, 0.1)
>>> assert result == "one"
>>> updated_array1 = await client.lrange("testKey1", 0, -1)
>>> updated_array2 = await client.lrange("testKey2", 0, -1)
>>> assert updated_array1 == ["two"]
>>> assert updated_array2 == ["one", "three", "four"]
>>> await client.blmove("testKey1", "testKey2", ListDirection.LEFT, ListDirection.LEFT, 0.1)
"one"
>>> await client.lrange("testKey1", 0, -1)
["two"]
>>> await client.lrange("testKey2", 0, -1)
["one", "three", "four"]

of the list stored at `destination` depending on `whereto`.
`blmove` is the blocking variant of `lmove`.

See https://redis.io/commands/blmove/ for details.
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
See https://redis.io/commands/blmove/ for details.
See https://valkey.io/commands/blmove/ for details.

Notes:
When in cluster mode, both `source` and `destination` must map to the same hash slot.

See https://redis.io/commands/lmove/ for details.
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
See https://redis.io/commands/lmove/ for details.
See https://valkey.io/commands/lmove/ for details.

1. When in cluster mode, both `source` and `destination` must map to the same hash slot.
2. `blmove` is a client blocking command, see https://github.com/aws/glide-for-redis/wiki/General-Concepts#blocking-commands for more details and best practices.

See https://redis.io/commands/blmove/ for details.
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
See https://redis.io/commands/blmove/ for details.
See https://valkey.io/commands/blmove/ for details.

depending on `wherefrom`, and pushes the element at the first/last element of the list
stored at `destination` depending on `whereto`.

See https://redis.io/commands/lmove/ for details.
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
See https://redis.io/commands/lmove/ for details.
See https://valkey.io/commands/lmove/ for details.

Comment on lines 1503 to 1504
wherefrom: ListDirection,
whereto: ListDirection,
Copy link
Collaborator

Choose a reason for hiding this comment

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

in python the syntax is:

Suggested change
wherefrom: ListDirection,
whereto: ListDirection,
where_from: ListDirection,
where_to: ListDirection,

whereto (ListDirection): The direction to add the element to (`ListDirection.LEFT` or `ListDirection.RIGHT`).

Returns:
Optional[str]: The popped element, or `None` if `source` does not exist.
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
Optional[str]: The popped element, or `None` if `source` does not exist.
Optional[str]: The popped element, or None if `source` does not exist.

self,
source: str,
destination: str,
wherefrom: ListDirection,
Copy link
Collaborator

Choose a reason for hiding this comment

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

same

Blocks the connection until it pops atomically and removes the left/right-most element to the
list stored at `source` depending on `wherefrom`, and pushes the element at the first/last element
of the list stored at `destination` depending on `whereto`.
`blmove` is the blocking variant of `lmove`.
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
`blmove` is the blocking variant of `lmove`.
`BLMOVE` is the blocking variant of `LMOVE`.

see other blocking commands

) -> Optional[str]:
"""
Atomically pops and removes the left/right-most element to the list stored at `source`
depending on `wherefrom`, and pushes the element at the first/last element of the list
Copy link
Contributor

Choose a reason for hiding this comment

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

if you change as per Sho's suggestions, please update here too

python/python/tests/test_async_client.py Show resolved Hide resolved
Copy link
Collaborator

@Yury-Fridlyand Yury-Fridlyand left a comment

Choose a reason for hiding this comment

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

Please add changelog entry

python/python/glide/async_commands/core.py Show resolved Hide resolved
python/python/glide/async_commands/core.py Show resolved Hide resolved
Comment on lines 964 to 965
Notes:
When in cluster mode, both `source` and `destination` must map to the same hash slot.
Copy link
Collaborator

Choose a reason for hiding this comment

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

We don't add this to transction.
It is applicable to the entire transaction, rather than to a particular command(s) in it.

Please Add since section

python/python/tests/test_async_client.py 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
python/python/tests/test_transaction.py Show resolved Hide resolved
@valkey-io valkey-io deleted a comment from shohamazon Jun 9, 2024
CHANGELOG.md Outdated Show resolved Hide resolved
python/python/tests/test_async_client.py Outdated Show resolved Hide resolved
python/python/tests/test_async_client.py Outdated Show resolved Hide resolved
Co-authored-by: Shoham Elias <116083498+shohamazon@users.noreply.github.com>
@GilboaAWS GilboaAWS merged commit ddc1425 into valkey-io:main Jun 9, 2024
6 checks passed
@GilboaAWS GilboaAWS deleted the lmove_python branch June 9, 2024 15:08
cyip10 pushed a commit to Bit-Quill/valkey-glide that referenced this pull request Jun 24, 2024
Python: added LMOVE and BLMOVE commands

Co-authored-by: Shoham Elias
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.

4 participants