-
Notifications
You must be signed in to change notification settings - Fork 65
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
Changes from 1 commit
e5992cf
80aabb3
c2f99a2
d63be4f
34d8682
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -16,7 +16,7 @@ | |||||||||||||||||||||||||
get_args, | ||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
from glide.async_commands.command_args import Limit, OrderBy | ||||||||||||||||||||||||||
from glide.async_commands.command_args import Limit, ListDirection, OrderBy | ||||||||||||||||||||||||||
from glide.async_commands.sorted_set import ( | ||||||||||||||||||||||||||
AggregationType, | ||||||||||||||||||||||||||
InfBound, | ||||||||||||||||||||||||||
|
@@ -1496,6 +1496,94 @@ async def linsert( | |||||||||||||||||||||||||
), | ||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
async def lmove( | ||||||||||||||||||||||||||
self, | ||||||||||||||||||||||||||
source: str, | ||||||||||||||||||||||||||
destination: str, | ||||||||||||||||||||||||||
wherefrom: ListDirection, | ||||||||||||||||||||||||||
whereto: ListDirection, | ||||||||||||||||||||||||||
) -> 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 | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if you change as per Sho's suggestions, please update here too |
||||||||||||||||||||||||||
stored at `destination` depending on `whereto`. | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
GilboaAWS marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||
See https://redis.io/commands/lmove/ for details. | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
Args: | ||||||||||||||||||||||||||
source (str): The key to the source list. | ||||||||||||||||||||||||||
destination (str): The key to the destination list. | ||||||||||||||||||||||||||
wherefrom (ListDirection): The direction to remove the element from (`ListDirection.LEFT` or `ListDirection.RIGHT`). | ||||||||||||||||||||||||||
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. | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
Examples: | ||||||||||||||||||||||||||
>>> await client.lpush("testKey1", ["two", "one"]) | ||||||||||||||||||||||||||
>>> await client.lpush("testKey2", ["four", "three"]) | ||||||||||||||||||||||||||
>>> result = await client.lmove("testKey1", "testKey2", ListDirection.LEFT, ListDirection.LEFT) | ||||||||||||||||||||||||||
>>> assert result == "one" | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"] | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||
return cast( | ||||||||||||||||||||||||||
Optional[str], | ||||||||||||||||||||||||||
await self._execute_command( | ||||||||||||||||||||||||||
RequestType.LMove, [source, destination, wherefrom.value, whereto.value] | ||||||||||||||||||||||||||
), | ||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
async def blmove( | ||||||||||||||||||||||||||
self, | ||||||||||||||||||||||||||
source: str, | ||||||||||||||||||||||||||
destination: str, | ||||||||||||||||||||||||||
wherefrom: ListDirection, | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same |
||||||||||||||||||||||||||
whereto: ListDirection, | ||||||||||||||||||||||||||
timeout: float, | ||||||||||||||||||||||||||
) -> Optional[str]: | ||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||
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`. | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
see other blocking commands |
||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
Notes: | ||||||||||||||||||||||||||
GilboaAWS marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||
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. | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
Args: | ||||||||||||||||||||||||||
source (str): The key to the source list. | ||||||||||||||||||||||||||
destination (str): The key to the destination list. | ||||||||||||||||||||||||||
wherefrom (ListDirection): The direction to remove the element from (`ListDirection.LEFT` or `ListDirection.RIGHT`). | ||||||||||||||||||||||||||
whereto (ListDirection): The direction to add the element to (`ListDirection.LEFT` or `ListDirection.RIGHT`). | ||||||||||||||||||||||||||
timeout (float): The number of seconds to wait for a blocking operation to complete. A value of `0` will block indefinitely. | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
Returns: | ||||||||||||||||||||||||||
Optional[str]: The popped element, or `None` if `source` does not exist or if the operation timed-out. | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
Examples: | ||||||||||||||||||||||||||
>>> await client.lpush("testKey1", ["two", "one"]) | ||||||||||||||||||||||||||
>>> await client.lpush("testKey2", ["four", "three"]) | ||||||||||||||||||||||||||
>>> 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"] | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||
return cast( | ||||||||||||||||||||||||||
Optional[str], | ||||||||||||||||||||||||||
await self._execute_command( | ||||||||||||||||||||||||||
RequestType.BLMove, | ||||||||||||||||||||||||||
[source, destination, wherefrom.value, whereto.value, str(timeout)], | ||||||||||||||||||||||||||
), | ||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
async def sadd(self, key: str, members: List[str]) -> int: | ||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||
Add specified members to the set stored at `key`. | ||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -3,7 +3,7 @@ | |||||
import threading | ||||||
from typing import List, Mapping, Optional, Tuple, TypeVar, Union | ||||||
|
||||||
from glide.async_commands.command_args import Limit, OrderBy | ||||||
from glide.async_commands.command_args import Limit, ListDirection, OrderBy | ||||||
from glide.async_commands.core import ( | ||||||
ConditionalChange, | ||||||
ExpireOptions, | ||||||
|
@@ -949,6 +949,67 @@ def linsert( | |||||
RequestType.LInsert, [key, position.value, pivot, element] | ||||||
) | ||||||
|
||||||
def lmove( | ||||||
self: TTransaction, | ||||||
source: str, | ||||||
destination: str, | ||||||
wherefrom: ListDirection, | ||||||
whereto: ListDirection, | ||||||
) -> TTransaction: | ||||||
""" | ||||||
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 | ||||||
stored at `destination` depending on `whereto`. | ||||||
|
||||||
Notes: | ||||||
When in cluster mode, both `source` and `destination` must map to the same hash slot. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't add this to transction. Please Add since section |
||||||
|
||||||
See https://redis.io/commands/lmove/ for details. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
Args: | ||||||
source (str): The key to the source list. | ||||||
destination (str): The key to the destination list. | ||||||
wherefrom (ListDirection): The direction to remove the element from (`ListDirection.LEFT` or `ListDirection.RIGHT`). | ||||||
whereto (ListDirection): The direction to add the element to (`ListDirection.LEFT` or `ListDirection.RIGHT`). | ||||||
|
||||||
Command response: | ||||||
Optional[str]: The popped element, or `None` if `source` does not exist. | ||||||
""" | ||||||
return self.append_command( | ||||||
RequestType.LMove, [source, destination, wherefrom.value, whereto.value] | ||||||
) | ||||||
|
||||||
def blmove( | ||||||
self: TTransaction, | ||||||
source: str, | ||||||
destination: str, | ||||||
wherefrom: ListDirection, | ||||||
whereto: ListDirection, | ||||||
timeout: float, | ||||||
) -> TTransaction: | ||||||
""" | ||||||
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`. | ||||||
|
||||||
See https://redis.io/commands/blmove/ for details. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
GilboaAWS marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
Args: | ||||||
source (str): The key to the source list. | ||||||
destination (str): The key to the destination list. | ||||||
wherefrom (ListDirection): The direction to remove the element from (`ListDirection.LEFT` or `ListDirection.RIGHT`). | ||||||
whereto (ListDirection): The direction to add the element to (`ListDirection.LEFT` or `ListDirection.RIGHT`). | ||||||
timeout (float): The number of seconds to wait for a blocking operation to complete. A value of `0` will block indefinitely. | ||||||
|
||||||
Command response: | ||||||
Optional[str]: The popped element, or `None` if `source` does not exist or if the operation timed-out. | ||||||
""" | ||||||
return self.append_command( | ||||||
RequestType.BLMove, | ||||||
[source, destination, wherefrom.value, whereto.value, str(timeout)], | ||||||
) | ||||||
|
||||||
def sadd(self: TTransaction, key: str, members: List[str]) -> TTransaction: | ||||||
""" | ||||||
Add specified members to the set stored at `key`. | ||||||
|
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 python the syntax is: