Skip to content

Commit

Permalink
add error for limit
Browse files Browse the repository at this point in the history
  • Loading branch information
shohamazon committed May 1, 2024
1 parent 26f9e18 commit 16624d3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
17 changes: 12 additions & 5 deletions python/python/glide/async_commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,11 @@ def __init__(
Otherwise the stream will be trimmed in a near-exact manner, which is more efficient.
threshold (Union[str, int]): Threshold for trimming.
method (str): Method for trimming (e.g., MINID, MAXLEN).
limit (Optional[int], optional): Max number of entries to be trimmed. Defaults to None.
limit (Optional[int]): Max number of entries to be trimmed. Defaults to None.
Note: If `exact` is set to `True`, `limit` cannot be specified.
"""
if exact and limit:
raise ValueError("LIMIT cannot be used without the special ~ option.")
self.exact = exact
self.threshold = threshold
self.method = method
Expand Down Expand Up @@ -207,7 +210,8 @@ def __init__(self, exact: bool, threshold: str, limit: Optional[int] = None):
exact (bool): If `true`, the stream will be trimmed exactly.
Otherwise the stream will be trimmed in a near-exact manner, which is more efficient.
threshold (str): Threshold for trimming by minimum ID.
limit (Optional[int], optional): Max number of entries to be trimmed. Defaults to None.
limit (Optional[int]): Max number of entries to be trimmed. Defaults to None.
Note: If `exact` is set to `True`, `limit` cannot be specified.
"""
super().__init__(exact, threshold, "MINID", limit)

Expand All @@ -225,7 +229,8 @@ def __init__(self, exact: bool, threshold: int, limit: Optional[int] = None):
exact (bool): If `true`, the stream will be trimmed exactly.
Otherwise the stream will be trimmed in a near-exact manner, which is more efficient.
threshold (int): Threshold for trimming by maximum length.
limit (Optional[int], optional): Max number of entries to be trimmed. Defaults to None.
limit (Optional[int]): Max number of entries to be trimmed. Defaults to None.
Note: If `exact` is set to `True`, `limit` cannot be specified.
"""
super().__init__(exact, threshold, "MAXLEN", limit)

Expand Down Expand Up @@ -1724,7 +1729,7 @@ async def xadd(
self,
key: str,
values: List[Tuple[str, str]],
options: StreamAddOptions = StreamAddOptions(),
options: Optional[StreamAddOptions] = None,
) -> Optional[str]:
"""
Adds an entry to the specified stream stored at `key`. If the `key` doesn't exist, the stream is created.
Expand All @@ -1734,7 +1739,7 @@ async def xadd(
Args:
key (str): The key of the stream.
values (List[Tuple[str, str]]): Field-value pairs to be added to the entry.
options (StreamAddOptions, optional): Additional options for adding entries to the stream. See `StreamAddOptions`.
options (Optional[StreamAddOptions]): Additional options for adding entries to the stream. Default to None. sSee `StreamAddOptions`.
Returns:
str: The id of the added entry, or None if `options.make_stream` is set to False and no stream with the matching `key` exists.
Expand All @@ -1750,6 +1755,8 @@ async def xadd(
args = [key]
if options:
args.extend(options.to_args())
else:
args.append("*")
args.extend([field for pair in values for field in pair])

return cast(Optional[str], await self._execute_command(RequestType.XAdd, args))
Expand Down
2 changes: 1 addition & 1 deletion python/python/glide/async_commands/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -1208,7 +1208,7 @@ def xadd(
Args:
key (str): The key of the stream.
values (List[Tuple[str, str]]): Field-value pairs to be added to the entry.
options (StreamAddOptions, optional): Additional options for adding entries to the stream. See `StreamAddOptions`.
options (Optional[StreamAddOptions]): Additional options for adding entries to the stream. Default to None. sSee `StreamAddOptions`.
Commands response:
str: The id of the added entry, or None if `options.make_stream` is set to False and no stream with the matching `key` exists.
Expand Down

0 comments on commit 16624d3

Please sign in to comment.