summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAndy McCurdy <andy@andymccurdy.com>2018-11-14 20:24:11 -0800
committerAndy McCurdy <andy@andymccurdy.com>2018-11-14 20:24:11 -0800
commit6d6e1a97625839d882f5b9080038e99d1e58e57b (patch)
tree7eafb9bd433fbfb9d58d89517953e75dab9402b9 /tests
parentd8b715734519982d18cdbdbb86339cd76d4ef7f9 (diff)
downloadredis-py-6d6e1a97625839d882f5b9080038e99d1e58e57b.tar.gz
add nx, xx, ch and incr options to ZADD
Fixes #649 Fixes #954 Fixes #638 Fixes #721 Fixes #955
Diffstat (limited to 'tests')
-rw-r--r--tests/test_commands.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/test_commands.py b/tests/test_commands.py
index ade8ecc..c8f259c 100644
--- a/tests/test_commands.py
+++ b/tests/test_commands.py
@@ -979,6 +979,40 @@ class TestRedisCommands(object):
assert r.zrange('a', 0, -1, withscores=True) == \
[(b'a1', 1.0), (b'a2', 2.0), (b'a3', 3.0)]
+ # error cases
+ with pytest.raises(exceptions.DataError):
+ r.zadd('a', {})
+
+ # cannot use both nx and xx options
+ with pytest.raises(exceptions.DataError):
+ r.zadd('a', mapping, nx=True, xx=True)
+
+ # cannot use the incr options with more than one value
+ with pytest.raises(exceptions.DataError):
+ r.zadd('a', mapping, incr=True)
+
+ def test_zadd_nx(self, r):
+ assert r.zadd('a', {'a1': 1}) == 1
+ assert r.zadd('a', {'a1': 99, 'a2': 2}, nx=True) == 1
+ assert r.zrange('a', 0, -1, withscores=True) == \
+ [(b'a1', 1.0), (b'a2', 2.0)]
+
+ def test_zadd_xx(self, r):
+ assert r.zadd('a', {'a1': 1}) == 1
+ assert r.zadd('a', {'a1': 99, 'a2': 2}, xx=True) == 0
+ assert r.zrange('a', 0, -1, withscores=True) == \
+ [(b'a1', 99.0)]
+
+ def test_zadd_ch(self, r):
+ assert r.zadd('a', {'a1': 1}) == 1
+ assert r.zadd('a', {'a1': 99, 'a2': 2}, ch=True) == 2
+ assert r.zrange('a', 0, -1, withscores=True) == \
+ [(b'a2', 2.0), (b'a1', 99.0)]
+
+ def test_zadd_incr(self, r):
+ assert r.zadd('a', {'a1': 1}) == 1
+ assert r.zadd('a', {'a1': 4.5}, incr=True) == 5.5
+
def test_zcard(self, r):
r.zadd('a', {'a1': 1, 'a2': 2, 'a3': 3})
assert r.zcard('a') == 3