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

fixed problems in #143 #144

Merged
merged 2 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -1320,6 +1320,26 @@ def test_get_and_set(self, r):
assert r.get("integer") == str(integer).encode()
assert r.get("unicode_string").decode("utf-8") == unicode_string

def test_set_options_mutually_exclusive(self, r):
with pytest.raises(exceptions.DataError):
r.set("test", 1, ex=1, px=1)

with pytest.raises(exceptions.DataError):
r.set("test2", 2, exat=3, pxat=5)

with pytest.raises(exceptions.DataError):
r.set("test3", 3, ex=5, exat=1)

def test_set_options_type_check(self, r):
with pytest.raises(exceptions.DataError):
r.set("test", 1, ex="hi")

with pytest.raises(exceptions.DataError):
r.set("test1", 3, px=object())

with pytest.raises(exceptions.DataError):
r.set("test3", 1, pxat=3j)

@skip_if_server_version_lt("6.2.0")
def test_getdel(self, r):
assert r.getdel("a") is None
Expand Down
5 changes: 5 additions & 0 deletions valkey/commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2287,6 +2287,11 @@ def set(

For more information see https://valkey.io/commands/set
"""
params = sum(op is not None for op in [ex, px, exat, pxat])
if params > 1:
raise DataError(
"``ex``, ``px``, ``exat`` and ``pxat`` " "are mutually exclusive."
)
pieces: list[EncodableT] = [name, value]
options = {}
if ex is not None:
Expand Down
Loading