Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

use available classes from redis-py

  • Loading branch information...
commit 9c6fa81458d2a40ab8566d0e8dfaddd1d29ff6ba 1 parent acf577e
Salimane Adjao Moustapha authored
4 rediscluster/__init__.py
View
@@ -1,5 +1,5 @@
-from rediscluster.client import (
- StrictRedis,
+from rediscluster.client import StrictRedis
+from redis.exceptions import (
AuthenticationError,
ConnectionError,
DataError,
53 rediscluster/_compat.py
View
@@ -1,53 +0,0 @@
-"""Internal module for Python 2 backwards compatibility."""
-import sys
-
-
-if sys.version_info[0] < 3:
- from urlparse import urlparse
- from itertools import imap, izip
- from string import letters as ascii_letters
- try:
- from cStringIO import StringIO as BytesIO
- except ImportError:
- from StringIO import StringIO as BytesIO
-
- iteritems = lambda x: x.iteritems()
- dictkeys = lambda x: x.keys()
- dictvalues = lambda x: x.values()
- nativestr = lambda x: \
- x if isinstance(x, str) else x.encode('utf-8', 'replace')
- u = lambda x: x.decode()
- b = lambda x: x
- next = lambda x: x.next()
- byte_to_chr = lambda x: x
- unichr = unichr
- xrange = xrange
- basestring = basestring
- unicode = unicode
- bytes = str
- long = long
-else:
- from urllib.parse import urlparse
- from io import BytesIO
- from string import ascii_letters
-
- def execfile(file, globals=globals(), locals=locals()):
- exec(compile(open(file).read(), file, 'exec'), globals, locals)
-
- iteritems = lambda x: x.items()
- dictkeys = lambda x: list(x.keys())
- dictvalues = lambda x: list(x.values())
- byte_to_chr = lambda x: chr(x)
- nativestr = lambda x: \
- x if isinstance(x, str) else x.decode('utf-8', 'replace')
- u = lambda x: x
- b = lambda x: x.encode('iso-8859-1') if not isinstance(x, bytes) else x
- next = next
- unichr = chr
- imap = map
- izip = zip
- xrange = range
- basestring = str
- unicode = str
- bytes = bytes
- long = int
21 rediscluster/client.py
View
@@ -1,18 +1,7 @@
# -*- coding: UTF-8 -*-
import redis
import binascii
-from rediscluster._compat import (b, iteritems, dictvalues)
-
-from redis.exceptions import (
- AuthenticationError,
- ConnectionError,
- DataError,
- InvalidResponse,
- PubSubError,
- RedisError,
- ResponseError,
- WatchError,
-)
+from redis._compat import (b, iteritems, dictvalues)
class StrictRedis:
"""
@@ -103,7 +92,7 @@ def __init__(self, cluster={}, db=0):
self.__redis = redis.StrictRedis(host=server['host'], port=server['port'], db=db)
sla = self.__redis.config_get('slaveof')['slaveof']
if alias in slaves and sla == '':
- raise DataError("rediscluster: server %s:%s is not a slave." % (server['host'], server['port']))
+ raise redis.DataError("rediscluster: server %s:%s is not a slave." % (server['host'], server['port']))
except Exception as e:
#if node is slave and is down, replace its connection with its master's
try:
@@ -117,10 +106,10 @@ def __init__(self, cluster={}, db=0):
self.__redis = redis.StrictRedis(host=cluster['nodes'][ms]['host'], port=cluster['nodes'][ms]['port'], db=db)
self.__redis.info()
except Exception as e:
- raise ConnectionError("rediscluster cannot connect to: %s:%s %s" % (cluster['nodes'][ms]['host'], cluster['nodes'][ms]['port'], e))
+ raise redis.ConnectionError("rediscluster cannot connect to: %s:%s %s" % (cluster['nodes'][ms]['host'], cluster['nodes'][ms]['port'], e))
else:
- raise ConnectionError("rediscluster cannot connect to: %s:%s %s" % (server['host'], server['port'], e))
+ raise redis.ConnectionError("rediscluster cannot connect to: %s:%s %s" % (server['host'], server['port'], e))
self.redises[alias] = self.__redis
@@ -137,7 +126,7 @@ def function(*args, **kwargs):
try:
return getattr(self, 'rc_'+name)(*args, **kwargs)
except AttributeError:
- raise DataError("SmartRedisCluster: Command %s Not Supported (each key name has its own node)" % name)
+ raise redis.DataError("SmartRedisCluster: Command %s Not Supported (each key name has its own node)" % name)
#get the hash key depending on tags or not
hkey = args[0]
2  tests/server_commands.py
View
@@ -5,7 +5,7 @@
from tests import config
import binascii
-from rediscluster._compat import (unichr, u, b, ascii_letters, iteritems, dictkeys,
+from redis._compat import (unichr, u, b, ascii_letters, iteritems, dictkeys,
dictvalues)
import rediscluster
Please sign in to comment.
Something went wrong with that request. Please try again.