summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy McCurdy <andy@andymccurdy.com>2018-12-27 16:03:36 -0800
committerAndy McCurdy <andy@andymccurdy.com>2018-12-27 16:03:36 -0800
commit8fc8fbd7210f5e0b03a119fab99e2d5f21622def (patch)
tree7dfb92f1089b5395fb544cd31c03b4c90d617536
parentc9466a1a9bf29593704c8ca52217c17eb3962b4a (diff)
downloadredis-py-8fc8fbd7210f5e0b03a119fab99e2d5f21622def.tar.gz
ZADD correctly returns None in certain edge cases when incr=True
When incr=True and xx=True and an element is specified that doesn't exist the Redis server returns None. redis-py now does this as well. Fixes #1084
-rw-r--r--CHANGES3
-rwxr-xr-xredis/client.py2
-rw-r--r--tests/test_commands.py6
3 files changed, 11 insertions, 0 deletions
diff --git a/CHANGES b/CHANGES
index a48933c..952cdda 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,4 +1,7 @@
* 3.0.2 (in development)
+ * ZADD now returns None when xx=True and incr=True and an element
+ is specified that doesn't exist in the sorted set. This matches
+ what the server returns in this case. #1084
* Added client_kill_filter that accepts various filters to identify
and kill clients. Thanks Theofanis Despoudis. #1098
* Fixed a race condition that occurred when unsubscribing and
diff --git a/redis/client.py b/redis/client.py
index 4f08fbd..c0d738c 100755
--- a/redis/client.py
+++ b/redis/client.py
@@ -307,6 +307,8 @@ def bool_ok(response):
def parse_zadd(response, **options):
+ if response is None:
+ return None
if options.get('as_score'):
return float(response)
return int(response)
diff --git a/tests/test_commands.py b/tests/test_commands.py
index 144b94c..71c0f18 100644
--- a/tests/test_commands.py
+++ b/tests/test_commands.py
@@ -1073,6 +1073,12 @@ class TestRedisCommands(object):
assert r.zadd('a', {'a1': 1}) == 1
assert r.zadd('a', {'a1': 4.5}, incr=True) == 5.5
+ def test_zadd_incr_with_xx(self, r):
+ # this asks zadd to incr 'a1' only if it exists, but it clearly
+ # doesn't. Redis returns a null value in this case and so should
+ # redis-py
+ assert r.zadd('a', {'a1': 1}, xx=True, incr=True) is None
+
def test_zcard(self, r):
r.zadd('a', {'a1': 1, 'a2': 2, 'a3': 3})
assert r.zcard('a') == 3