Skip to content

Commit 3c0e116

Browse files
authored
exclusive gt and lt in zadd (#1533)
* exclusive gt and lt in zadd * docs update
1 parent 6f4ee2d commit 3c0e116

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

redis/client.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2892,9 +2892,18 @@ def zadd(self, name, mapping, nx=False, xx=False, ch=False, incr=False,
28922892
the existing score will be incremented by. When using this mode the
28932893
return value of ZADD will be the new score of the element.
28942894
2895+
``LT`` Only update existing elements if the new score is less than
2896+
the current score. This flag doesn't prevent adding new elements.
2897+
2898+
``GT`` Only update existing elements if the new score is greater than
2899+
the current score. This flag doesn't prevent adding new elements.
2900+
28952901
The return value of ZADD varies based on the mode specified. With no
28962902
options, ZADD returns the number of new elements added to the sorted
28972903
set.
2904+
2905+
``NX``, ``LT``, and ``GT`` are mutually exclusive options.
2906+
See: https://redis.io/commands/ZADD
28982907
"""
28992908
if not mapping:
29002909
raise DataError("ZADD requires at least one element/score pair")
@@ -2904,7 +2913,9 @@ def zadd(self, name, mapping, nx=False, xx=False, ch=False, incr=False,
29042913
raise DataError("ZADD option 'incr' only works when passing a "
29052914
"single element/score pair")
29062915
if nx is True and (gt is not None or lt is not None):
2907-
raise DataError("Only one of 'nx', 'lt', or 'gr' may be defined.")
2916+
raise DataError("Only one of 'nx', 'lt', or 'gt' may be defined.")
2917+
if gt is not None and lt is not None:
2918+
raise DataError("Only one of 'gt' or 'lt' can be set.")
29082919

29092920
pieces = []
29102921
options = {}

0 commit comments

Comments
 (0)