Skip to content

Commit f8fc065

Browse files
authored
Merge pull request #144 from amirreza8002/main
fixed problems in #143
2 parents 013fef0 + fbb232e commit f8fc065

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

tests/test_commands.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,6 +1320,26 @@ def test_get_and_set(self, r):
13201320
assert r.get("integer") == str(integer).encode()
13211321
assert r.get("unicode_string").decode("utf-8") == unicode_string
13221322

1323+
def test_set_options_mutually_exclusive(self, r):
1324+
with pytest.raises(exceptions.DataError):
1325+
r.set("test", 1, ex=1, px=1)
1326+
1327+
with pytest.raises(exceptions.DataError):
1328+
r.set("test2", 2, exat=3, pxat=5)
1329+
1330+
with pytest.raises(exceptions.DataError):
1331+
r.set("test3", 3, ex=5, exat=1)
1332+
1333+
def test_set_options_type_check(self, r):
1334+
with pytest.raises(exceptions.DataError):
1335+
r.set("test", 1, ex="hi")
1336+
1337+
with pytest.raises(exceptions.DataError):
1338+
r.set("test1", 3, px=object())
1339+
1340+
with pytest.raises(exceptions.DataError):
1341+
r.set("test3", 1, pxat=3j)
1342+
13231343
@skip_if_server_version_lt("6.2.0")
13241344
def test_getdel(self, r):
13251345
assert r.getdel("a") is None

valkey/commands/core.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2287,6 +2287,11 @@ def set(
22872287
22882288
For more information see https://valkey.io/commands/set
22892289
"""
2290+
params = sum(op is not None for op in [ex, px, exat, pxat])
2291+
if params > 1:
2292+
raise DataError(
2293+
"``ex``, ``px``, ``exat`` and ``pxat`` " "are mutually exclusive."
2294+
)
22902295
pieces: list[EncodableT] = [name, value]
22912296
options = {}
22922297
if ex is not None:

0 commit comments

Comments
 (0)