summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy McCurdy <andy@andymccurdy.com>2010-05-23 07:39:44 -0700
committerAndy McCurdy <andy@andymccurdy.com>2010-05-23 07:39:44 -0700
commitdd8421273d4b17adfda56e8b753bdf92d4d43fb5 (patch)
tree3c0517172f1ecf62dedb4df671a5b4e16f66a5a9
parent2b07bd7ad65d4fdee11e1a3dba65180dd920cf75 (diff)
downloadredis-py-dd8421273d4b17adfda56e8b753bdf92d4d43fb5.tar.gz
renamed zinter/zunion to zinterstore/zunionstore to stay consistent with Redis.
-rw-r--r--redis/client.py16
-rw-r--r--tests/server_commands.py20
2 files changed, 26 insertions, 10 deletions
diff --git a/redis/client.py b/redis/client.py
index d6932d1..eb58657 100644
--- a/redis/client.py
+++ b/redis/client.py
@@ -925,12 +925,18 @@ class Redis(threading.local):
return self.execute_command('ZINCRBY', name, amount, value)
def zinter(self, dest, keys, aggregate=None):
+ warnings.warn(DeprecationWarning(
+ "Redis.zinter has been deprecated, use Redis.zinterstore instead"
+ ))
+ return self.zinterstore(dest, keys, aggregate)
+
+ def zinterstore(self, dest, keys, aggregate=None):
"""
Intersect multiple sorted sets specified by ``keys`` into
a new sorted set, ``dest``. Scores in the destination will be
aggregated based on the ``aggregate``, or SUM if none is provided.
"""
- return self._zaggregate('ZINTER', dest, keys, aggregate)
+ return self._zaggregate('ZINTERSTORE', dest, keys, aggregate)
def zrange(self, name, start, end, desc=False, withscores=False):
"""
@@ -1017,12 +1023,18 @@ class Redis(threading.local):
return self.execute_command('ZSCORE', name, value)
def zunion(self, dest, keys, aggregate=None):
+ warnings.warn(DeprecationWarning(
+ "Redis.zunion has been deprecated, use Redis.zunionstore instead"
+ ))
+ return self.zunionstore(dest, keys, aggregate)
+
+ def zunionstore(self, dest, keys, aggregate=None):
"""
Union multiple sorted sets specified by ``keys`` into
a new sorted set, ``dest``. Scores in the destination will be
aggregated based on the ``aggregate``, or SUM if none is provided.
"""
- return self._zaggregate('ZUNION', dest, keys, aggregate)
+ return self._zaggregate('ZUNIONSTORE', dest, keys, aggregate)
def _zaggregate(self, command, dest, keys, aggregate=None):
pieces = [command, dest, len(keys)]
diff --git a/tests/server_commands.py b/tests/server_commands.py
index 056188a..9024762 100644
--- a/tests/server_commands.py
+++ b/tests/server_commands.py
@@ -621,27 +621,29 @@ class ServerCommandsTestCase(unittest.TestCase):
self.assertEquals(self.client.zscore('a', 'a2'), 3.0)
self.assertEquals(self.client.zscore('a', 'a3'), 8.0)
- def test_zinter(self):
+ def test_zinterstore(self):
self.make_zset('a', {'a1': 1, 'a2': 1, 'a3': 1})
self.make_zset('b', {'a1': 2, 'a3': 2, 'a4': 2})
self.make_zset('c', {'a1': 6, 'a3': 5, 'a4': 4})
# sum, no weight
- self.assert_(self.client.zinter('z', ['a', 'b', 'c']))
+ self.assert_(self.client.zinterstore('z', ['a', 'b', 'c']))
self.assertEquals(
self.client.zrange('z', 0, -1, withscores=True),
[('a3', 8), ('a1', 9)]
)
# max, no weight
- self.assert_(self.client.zinter('z', ['a', 'b', 'c'], aggregate='MAX'))
+ self.assert_(
+ self.client.zinterstore('z', ['a', 'b', 'c'], aggregate='MAX')
+ )
self.assertEquals(
self.client.zrange('z', 0, -1, withscores=True),
[('a3', 5), ('a1', 6)]
)
# with weight
- self.assert_(self.client.zinter('z', {'a': 1, 'b': 2, 'c': 3}))
+ self.assert_(self.client.zinterstore('z', {'a': 1, 'b': 2, 'c': 3}))
self.assertEquals(
self.client.zrange('z', 0, -1, withscores=True),
[('a3', 20), ('a1', 23)]
@@ -764,27 +766,29 @@ class ServerCommandsTestCase(unittest.TestCase):
# test a non-existant member
self.assertEquals(self.client.zscore('a', 'a4'), None)
- def test_zunion(self):
+ def test_zunionstore(self):
self.make_zset('a', {'a1': 1, 'a2': 1, 'a3': 1})
self.make_zset('b', {'a1': 2, 'a3': 2, 'a4': 2})
self.make_zset('c', {'a1': 6, 'a4': 5, 'a5': 4})
# sum, no weight
- self.assert_(self.client.zunion('z', ['a', 'b', 'c']))
+ self.assert_(self.client.zunionstore('z', ['a', 'b', 'c']))
self.assertEquals(
self.client.zrange('z', 0, -1, withscores=True),
[('a2', 1), ('a3', 3), ('a5', 4), ('a4', 7), ('a1', 9)]
)
# max, no weight
- self.assert_(self.client.zunion('z', ['a', 'b', 'c'], aggregate='MAX'))
+ self.assert_(
+ self.client.zunionstore('z', ['a', 'b', 'c'], aggregate='MAX')
+ )
self.assertEquals(
self.client.zrange('z', 0, -1, withscores=True),
[('a2', 1), ('a3', 2), ('a5', 4), ('a4', 5), ('a1', 6)]
)
# with weight
- self.assert_(self.client.zunion('z', {'a': 1, 'b': 2, 'c': 3}))
+ self.assert_(self.client.zunionstore('z', {'a': 1, 'b': 2, 'c': 3}))
self.assertEquals(
self.client.zrange('z', 0, -1, withscores=True),
[('a2', 1), ('a3', 5), ('a5', 12), ('a4', 19), ('a1', 23)]