Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

don't reconnect if first attempt failed because it's already done in …

…redis-py
  • Loading branch information...
commit 27c1844e3c6c08ee420a3db18e8637675e2af582 1 parent 40e0233
@salimane authored
Showing with 15 additions and 25 deletions.
  1. +15 −25 rediscluster/client.py
View
40 rediscluster/client.py
@@ -104,32 +104,22 @@ def __init__(self, cluster={}, db=0):
if alias in slaves and sla == '':
raise 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:
- 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']))
- except Exception as e:
- #if node is slave and is down, replace its connection with its master's
+ ms = [k for k, v in iteritems(cluster['master_of'])
+ if v == alias and (sla != '' or cluster['nodes'][k]['host'] + str(cluster['nodes'][k]['port']) == cluster['nodes'][v]['host'] + str(cluster['nodes'][v]['port']))][0]
+ except IndexError:
+ ms = None
+
+ if ms is not None:
try:
- ms = [k for k, v in iteritems(cluster['master_of'])
- if v == alias and (sla != '' or cluster['nodes'][k]['host'] + str(cluster['nodes'][k]['port']) == cluster['nodes'][v]['host'] + str(cluster['nodes'][v]['port']))][0]
- except IndexError as ie:
- ms = None
-
- if ms is not None:
- try:
- self.__redis = redis.StrictRedis(host=cluster['nodes'][ms]['host'], port=cluster['nodes'][ms]['port'], db=db)
- self.__redis.info()
- except Exception as e:
- try:
- 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))
-
- else:
- raise ConnectionError("rediscluster cannot connect to: %s:%s %s" % (server['host'], server['port'], e))
+ 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))
+
+ else:
+ raise ConnectionError("rediscluster cannot connect to: %s:%s %s" % (server['host'], server['port'], e))
self.redises[alias] = self.__redis
@@ -145,7 +135,7 @@ def function(*args, **kwargs):
if name in StrictRedis.tag_keys and not isinstance(args[0], list) :
try:
return getattr(self, 'rc_'+name)(*args, **kwargs)
- except AttributeError as ae:
+ except AttributeError:
raise DataError("SmartRedisCluster: Command %s Not Supported (each key name has its own node)" % name)
#get the hash key depending on tags or not
Please sign in to comment.
Something went wrong with that request. Please try again.