Permalink
Browse files

rename files/classes for easy integration

  • Loading branch information...
salimane committed Sep 17, 2012
1 parent 0fbe14a commit f577debdc5ce906fa0b91b91d868e8e4eff120e7
View
@@ -67,7 +67,7 @@ Getting Started
... },
... 'default_node' : 'node_1'
... }
- >>> r = rediscluster.StrictRedis(cluster=cluster, db=0)
+ >>> r = rediscluster.StrictRedisCluster(cluster=cluster, db=0)
>>> r.set('foo', 'bar')
True
>>> r.get('foo')
View
@@ -1,4 +1,4 @@
-from rediscluster.client import StrictRedis
+from rediscluster.cluster_client import StrictRedisCluster
from redis.exceptions import (
AuthenticationError,
ConnectionError,
@@ -10,10 +10,10 @@
WatchError,
)
-__version__ = '0.2.4'
+__version__ = '0.2.5'
VERSION = tuple(map(int, __version__.split('.')))
__all__ = [
- 'StrictRedis', 'RedisError', 'ConnectionError', 'ResponseError', 'AuthenticationError',
+ 'StrictRedisCluster', 'RedisError', 'ConnectionError', 'ResponseError', 'AuthenticationError',
'InvalidResponse', 'DataError', 'PubSubError', 'WatchError'
-]
+]
@@ -3,9 +3,9 @@
import binascii
from redis._compat import (b, iteritems, dictvalues)
-class StrictRedis:
+class StrictRedisCluster:
"""
- Implementation of the Redis Cluster Client using redis.StrictRedis
+ Implementation of the Redis Cluster Client using redis.StrictRedisCluster
This abstract class provides a Python interface to all Redis commands on the cluster of redis servers.
and implementing how the commands are sent to and received from the cluster.
@@ -121,8 +121,8 @@ def __getattr__(self, name, *args, **kwargs):
- tuple args of supplied arguments to the command.
"""
def function(*args, **kwargs):
- if name not in StrictRedis._loop_keys:
- if name in StrictRedis._tag_keys and not isinstance(args[0], list) :
+ if name not in StrictRedisCluster._loop_keys:
+ if name in StrictRedisCluster._tag_keys and not isinstance(args[0], list) :
try:
return getattr(self, '_rc_' + name)(*args, **kwargs)
except AttributeError:
@@ -140,9 +140,9 @@ def function(*args, **kwargs):
#get the node number
node = str((abs(binascii.crc32(b(hkey)) & 0xffffffff) % self.no_servers) + 1)
redisent = self.redises[self.cluster['default_node']]
- if name in StrictRedis._write_keys:
+ if name in StrictRedisCluster._write_keys:
redisent = self.redises['node_' + node]
- elif name in StrictRedis._read_keys:
+ elif name in StrictRedisCluster._read_keys:
redisent = self.redises[self.cluster['master_of']['node_' + node]]
#Execute the command on the server
@@ -151,7 +151,7 @@ def function(*args, **kwargs):
else:
result = {}
for alias, redisent in iteritems(self.redises):
- if name in StrictRedis._write_keys and alias not in self.cluster['master_of']:
+ if name in StrictRedisCluster._write_keys and alias not in self.cluster['master_of']:
res = None
else:
res = getattr(redisent, name)(*args, **kwargs)
@@ -316,5 +316,4 @@ def _rc_mget(self, *args):
result.append(self.get(key))
return result
-
View
@@ -1,13 +1,7 @@
import unittest
-from tests.server_commands import ServerCommandsTestCase
-
-try:
- import hiredis
- use_hiredis = True
-except ImportError:
- use_hiredis = False
+from tests.cluster_commands import ClusterCommandsTestCase
def all_tests():
suite = unittest.TestSuite()
- suite.addTest(unittest.makeSuite(ServerCommandsTestCase))
+ suite.addTest(unittest.makeSuite(ClusterCommandsTestCase))
return suite
@@ -2,16 +2,16 @@
import unittest
import datetime
import time
-from tests import config
import binascii
from redis._compat import (unichr, u, b, ascii_letters, iteritems, dictkeys,
dictvalues)
from redis.client import parse_info
import rediscluster
+from tests import config
-class ServerCommandsTestCase(unittest.TestCase):
- def get_client(self, cls=rediscluster.StrictRedis):
+class ClusterCommandsTestCase(unittest.TestCase):
+ def get_client(self, cls=rediscluster.StrictRedisCluster):
return cls(cluster=config.cluster, db=4)
def setUp(self):
@@ -1538,13 +1538,13 @@ def test_sort_all_options(self):
[b('vodka'), b('milk'), b('gin'), b('apple juice')])
def test_strict_zadd(self):
- client = self.get_client(rediscluster.StrictRedis)
+ client = self.get_client(rediscluster.StrictRedisCluster)
client.zadd('a', 1.0, 'a1', 2.0, 'a2', a3=3.0)
self.assertEquals(client.zrange('a', 0, 3, withscores=True),
[(b('a1'), 1.0), (b('a2'), 2.0), (b('a3'), 3.0)])
def test_strict_lrem(self):
- client = self.get_client(rediscluster.StrictRedis)
+ client = self.get_client(rediscluster.StrictRedisCluster)
client.rpush('a', 'a1')
client.rpush('a', 'a2')
client.rpush('a', 'a3')
@@ -1554,14 +1554,14 @@ def test_strict_lrem(self):
def test_strict_setex(self):
"SETEX swaps the order of the value and timeout"
- client = self.get_client(rediscluster.StrictRedis)
+ client = self.get_client(rediscluster.StrictRedisCluster)
self.assertEquals(client.setex('a', 60, '1'), True)
self.assertEquals(client.get('a'), b('1'))
self.assertEquals(client.ttl('a'), 60)
def test_strict_expire(self):
"TTL is -1 by default in StrictRedis"
- client = self.get_client(rediscluster.StrictRedis)
+ client = self.get_client(rediscluster.StrictRedisCluster)
self.assertEquals(client.expire('a', 10), False)
self.client['a'] = 'foo'
self.assertEquals(client.expire('a', 10), True)

0 comments on commit f577deb

Please sign in to comment.