Skip to content

Commit

Permalink
Merge branch 'valkey-io:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
amirreza8002 authored Dec 10, 2024
2 parents 4fea0e4 + 1f6b63c commit 1bb0afe
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 2 additions & 0 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -1353,6 +1353,8 @@ def test_getdel(self, r):
@skip_if_server_version_lt("6.2.0")
def test_getex(self, r):
r.set("a", 1)
with pytest.raises(valkey.DataError):
r.getex("a", ex=10, px=10)
assert r.getex("a") == b"1"
assert r.ttl("a") == -1
assert r.getex("a", ex=60) == b"1"
Expand Down
13 changes: 8 additions & 5 deletions valkey/commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
from valkey.exceptions import ConnectionError, DataError, NoScriptError, ValkeyError
from valkey.typing import (
AbsExpiryT,
AnyEncodableT,
AnyFieldT,
AnyKeyT,
AnyStreamIdT,
BitfieldOffsetT,
ChannelT,
CommandsProtocol,
Expand Down Expand Up @@ -1859,8 +1862,8 @@ def getex(
For more information see https://valkey.io/commands/getex
"""

opset = {ex, px, exat, pxat}
if len(opset) > 2 or len(opset) > 1 and persist:
opvs = sum(op is not None for op in [ex, px, exat, pxat])
if opvs > 1 or (opvs and persist):
raise DataError(
"``ex``, ``px``, ``exat``, ``pxat``, "
"and ``persist`` are mutually exclusive."
Expand Down Expand Up @@ -3517,7 +3520,7 @@ def xack(self, name: KeyT, groupname: GroupT, *ids: StreamIdT) -> ResponseT:
def xadd(
self,
name: KeyT,
fields: Dict[FieldT, EncodableT],
fields: Mapping[AnyFieldT, AnyEncodableT],
id: StreamIdT = "*",
maxlen: Union[int, None] = None,
approximate: bool = True,
Expand Down Expand Up @@ -3942,7 +3945,7 @@ def xrange(

def xread(
self,
streams: Dict[KeyT, StreamIdT],
streams: Mapping[AnyKeyT, AnyStreamIdT],
count: Union[int, None] = None,
block: Union[int, None] = None,
) -> ResponseT:
Expand Down Expand Up @@ -3982,7 +3985,7 @@ def xreadgroup(
self,
groupname: str,
consumername: str,
streams: Dict[KeyT, StreamIdT],
streams: Mapping[AnyKeyT, AnyStreamIdT],
count: Union[int, None] = None,
block: Union[int, None] = None,
noack: bool = False,
Expand Down
2 changes: 2 additions & 0 deletions valkey/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
AnyKeyT = TypeVar("AnyKeyT", bytes, str, memoryview)
AnyFieldT = TypeVar("AnyFieldT", bytes, str, memoryview)
AnyChannelT = TypeVar("AnyChannelT", bytes, str, memoryview)
AnyStreamIdT = TypeVar("AnyStreamIdT", int, bytes, str, memoryview)
AnyEncodableT = TypeVar("AnyEncodableT", int, float, bytes, str, memoryview)

ExceptionMappingT = Mapping[str, Union[Type[Exception], Mapping[str, Type[Exception]]]]

Expand Down

0 comments on commit 1bb0afe

Please sign in to comment.