Skip to content

Commit

Permalink
exclusive gt and lt in zadd (#1533)
Browse files Browse the repository at this point in the history
* exclusive gt and lt in zadd

* docs update
  • Loading branch information
chayim committed Aug 3, 2021
1 parent 6f4ee2d commit 3c0e116
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion redis/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2892,9 +2892,18 @@ def zadd(self, name, mapping, nx=False, xx=False, ch=False, incr=False,
the existing score will be incremented by. When using this mode the
return value of ZADD will be the new score of the element.
``LT`` Only update existing elements if the new score is less than
the current score. This flag doesn't prevent adding new elements.
``GT`` Only update existing elements if the new score is greater than
the current score. This flag doesn't prevent adding new elements.
The return value of ZADD varies based on the mode specified. With no
options, ZADD returns the number of new elements added to the sorted
set.
``NX``, ``LT``, and ``GT`` are mutually exclusive options.
See: https://redis.io/commands/ZADD
"""
if not mapping:
raise DataError("ZADD requires at least one element/score pair")
Expand All @@ -2904,7 +2913,9 @@ def zadd(self, name, mapping, nx=False, xx=False, ch=False, incr=False,
raise DataError("ZADD option 'incr' only works when passing a "
"single element/score pair")
if nx is True and (gt is not None or lt is not None):
raise DataError("Only one of 'nx', 'lt', or 'gr' may be defined.")
raise DataError("Only one of 'nx', 'lt', or 'gt' may be defined.")
if gt is not None and lt is not None:
raise DataError("Only one of 'gt' or 'lt' can be set.")

pieces = []
options = {}
Expand Down

0 comments on commit 3c0e116

Please sign in to comment.