Skip to content

Commit 8a6acc2

Browse files
committed
change min_max parameter
1 parent 726b82e commit 8a6acc2

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

redis/commands/core.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3260,7 +3260,8 @@ def zmpop(
32603260
self,
32613261
num_keys: int,
32623262
keys: List[str],
3263-
min_max: str,
3263+
min: Optional[bool] = False,
3264+
max: Optional[bool] = False,
32643265
count: Optional[int] = 1,
32653266
) -> list:
32663267
"""
@@ -3269,7 +3270,13 @@ def zmpop(
32693270
32703271
For more information check https://redis.io/commands/zmpop
32713272
"""
3272-
args = [num_keys] + keys + [min_max]
3273+
args = [num_keys] + keys
3274+
if (min and max) or (not min and not max):
3275+
raise DataError
3276+
elif min:
3277+
args.append("MIN")
3278+
else:
3279+
args.append("MAX")
32733280
if count != 1:
32743281
args.extend(["COUNT", count])
32753282

tests/test_commands.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2063,11 +2063,11 @@ def test_bzpopmin(self, r):
20632063
def test_zmpop(self, unstable_r):
20642064
unstable_r.zadd("a", {"a1": 1, "a2": 2, "a3": 3})
20652065
res = [b"a", [[b"a1", b"1"], [b"a2", b"2"]]]
2066-
assert unstable_r.zmpop("2", ["b", "a"], "MIN", count=2) == res
2067-
with pytest.raises(TypeError):
2066+
assert unstable_r.zmpop("2", ["b", "a"], min=True, count=2) == res
2067+
with pytest.raises(redis.DataError):
20682068
unstable_r.zmpop("2", ["b", "a"], count=2)
20692069
unstable_r.zadd("b", {"b1": 10, "ab": 9, "b3": 8})
2070-
assert unstable_r.zmpop("2", ["b", "a"], "MAX") == [b"b", [[b"b1", b"10"]]]
2070+
assert unstable_r.zmpop("2", ["b", "a"], max=True) == [b"b", [[b"b1", b"10"]]]
20712071

20722072
def test_zrange(self, r):
20732073
r.zadd("a", {"a1": 1, "a2": 2, "a3": 3})

0 commit comments

Comments
 (0)