Skip to content

Commit

Permalink
Python: fix transaction publish documentation and typing (#1809)
Browse files Browse the repository at this point in the history
  • Loading branch information
shohamazon authored Jul 7, 2024
1 parent 6d73d6e commit 0edbfc3
Showing 1 changed file with 21 additions and 23 deletions.
44 changes: 21 additions & 23 deletions python/python/glide/async_commands/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -4830,14 +4830,14 @@ def select(self, index: int) -> "Transaction":
return self.append_command(RequestType.Select, [str(index)])

def sort(
self: TTransaction,
self,
key: TEncodable,
by_pattern: Optional[TEncodable] = None,
limit: Optional[Limit] = None,
get_patterns: Optional[List[TEncodable]] = None,
order: Optional[OrderBy] = None,
alpha: Optional[bool] = None,
) -> TTransaction:
) -> "Transaction":
"""
Sorts the elements in the list, set, or sorted set at `key` and returns the result.
The `sort` command can be used to sort elements based on different criteria and apply transformations on sorted elements.
Expand Down Expand Up @@ -4877,14 +4877,14 @@ def sort(
return self.append_command(RequestType.Sort, args)

def sort_ro(
self: TTransaction,
self,
key: TEncodable,
by_pattern: Optional[TEncodable] = None,
limit: Optional[Limit] = None,
get_patterns: Optional[List[TEncodable]] = None,
order: Optional[OrderBy] = None,
alpha: Optional[bool] = None,
) -> TTransaction:
) -> "Transaction":
"""
Sorts the elements in the list, set, or sorted set at `key` and returns the result.
The `sort_ro` command can be used to sort elements based on different criteria and apply transformations on sorted elements.
Expand Down Expand Up @@ -4926,15 +4926,15 @@ def sort_ro(
return self.append_command(RequestType.SortReadOnly, args)

def sort_store(
self: TTransaction,
self,
key: TEncodable,
destination: TEncodable,
by_pattern: Optional[TEncodable] = None,
limit: Optional[Limit] = None,
get_patterns: Optional[List[TEncodable]] = None,
order: Optional[OrderBy] = None,
alpha: Optional[bool] = None,
) -> TTransaction:
) -> "Transaction":
"""
Sorts the elements in the list, set, or sorted set at `key` and stores the result in `store`.
The `sort` command can be used to sort elements based on different criteria, apply transformations on sorted elements, and store the result in a new key.
Expand Down Expand Up @@ -4977,12 +4977,12 @@ def sort_store(
return self.append_command(RequestType.Sort, args)

def copy(
self: TTransaction,
self,
source: TEncodable,
destination: TEncodable,
destinationDB: Optional[int] = None,
replace: Optional[bool] = None,
) -> TTransaction:
) -> "Transaction":
"""
Copies the value stored at the `source` to the `destination` key. If `destinationDB`
is specified, the value will be copied to the database specified by `destinationDB`,
Expand Down Expand Up @@ -5010,9 +5010,7 @@ def copy(

return self.append_command(RequestType.Copy, args)

def publish(
self: TTransaction, message: TEncodable, channel: TEncodable
) -> TTransaction:
def publish(self, message: TEncodable, channel: TEncodable) -> "Transaction":
"""
Publish a message on pubsub channel.
See https://valkey.io/commands/publish for more details.
Expand All @@ -5021,8 +5019,8 @@ def publish(
message (TEncodable): Message to publish
channel (TEncodable): Channel to publish the message on.
Returns:
TOK: a simple `OK` response.
Command Respose:
int: Number of subscriptions in that shard that received the message.
"""
return self.append_command(RequestType.Publish, [channel, message])
Expand All @@ -5038,12 +5036,12 @@ class ClusterTransaction(BaseTransaction):
"""

def sort(
self: TTransaction,
self,
key: TEncodable,
limit: Optional[Limit] = None,
order: Optional[OrderBy] = None,
alpha: Optional[bool] = None,
) -> TTransaction:
) -> "ClusterTransaction":
"""
Sorts the elements in the list, set, or sorted set at `key` and returns the result.
This command is routed to primary only.
Expand All @@ -5066,12 +5064,12 @@ def sort(
return self.append_command(RequestType.Sort, args)

def sort_ro(
self: TTransaction,
self,
key: TEncodable,
limit: Optional[Limit] = None,
order: Optional[OrderBy] = None,
alpha: Optional[bool] = None,
) -> TTransaction:
) -> "ClusterTransaction":
"""
Sorts the elements in the list, set, or sorted set at `key` and returns the result.
The `sort_ro` command can be used to sort elements based on different criteria and apply transformations on sorted elements.
Expand All @@ -5096,13 +5094,13 @@ def sort_ro(
return self.append_command(RequestType.SortReadOnly, args)

def sort_store(
self: TTransaction,
self,
key: TEncodable,
destination: TEncodable,
limit: Optional[Limit] = None,
order: Optional[OrderBy] = None,
alpha: Optional[bool] = None,
) -> TTransaction:
) -> "ClusterTransaction":
"""
Sorts the elements in the list, set, or sorted set at `key` and stores the result in `store`.
When in cluster mode, `key` and `store` must map to the same hash slot.
Expand All @@ -5126,11 +5124,11 @@ def sort_store(
return self.append_command(RequestType.Sort, args)

def copy(
self: TTransaction,
self,
source: TEncodable,
destination: TEncodable,
replace: Optional[bool] = None,
) -> TTransaction:
) -> "ClusterTransaction":
"""
Copies the value stored at the `source` to the `destination` key. When `replace` is True,
removes the `destination` key first if it already exists, otherwise performs no action.
Expand All @@ -5154,8 +5152,8 @@ def copy(
return self.append_command(RequestType.Copy, args)

def publish(
self: TTransaction, message: str, channel: str, sharded: bool = False
) -> TTransaction:
self, message: str, channel: str, sharded: bool = False
) -> "ClusterTransaction":
"""
Publish a message on pubsub channel.
This command aggregates PUBLISH and SPUBLISH commands functionalities.
Expand Down

0 comments on commit 0edbfc3

Please sign in to comment.