summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--redis/client.py3
-rw-r--r--tests/server_commands.py11
2 files changed, 14 insertions, 0 deletions
diff --git a/redis/client.py b/redis/client.py
index 41a9660..8f63343 100644
--- a/redis/client.py
+++ b/redis/client.py
@@ -935,6 +935,9 @@ class Redis(threading.local):
"Return the number of elements in the sorted set ``name``"
return self.execute_command('ZCARD', name)
+ def zcount(self, name, min, max):
+ return self.execute_command('ZCOUNT', name, min, max)
+
def zincr(self, key, member, value=1):
"This has been deprecated, use zincrby instead"
warnings.warn(DeprecationWarning(
diff --git a/tests/server_commands.py b/tests/server_commands.py
index 81096e9..efcf2d6 100644
--- a/tests/server_commands.py
+++ b/tests/server_commands.py
@@ -615,6 +615,17 @@ class ServerCommandsTestCase(unittest.TestCase):
self.make_zset('a', {'a1': 1, 'a2': 2, 'a3': 3})
self.assertEquals(self.client.zcard('a'), 3)
+ def test_zcount(self):
+ # key is not a zset
+ self.client['a'] = 'a'
+ self.assertRaises(redis.ResponseError, self.client.zcount, 'a', 0, 0)
+ del self.client['a']
+ # real logic
+ self.make_zset('a', {'a1': 1, 'a2': 2, 'a3': 3})
+ self.assertEquals(self.client.zcount('a', '-inf', '+inf'), 3)
+ self.assertEquals(self.client.zcount('a', 1, 2), 2)
+ self.assertEquals(self.client.zcount('a', 10, 20), 0)
+
def test_zincrby(self):
# key is not a zset
self.client['a'] = 'a'