From bd19a43f51daa07a3c7081d8df723199f7b6ec2e Mon Sep 17 00:00:00 2001 From: Hendrik Demolder Date: Wed, 7 Aug 2019 14:27:44 +0200 Subject: [PATCH 1/7] remove redis version downgrade. Will probably brake stuff --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 91015469..7800f0fa 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -redis==2.10.6 +redis From e1654fbb8a176de18af5df8849fe778e0f05ef63 Mon Sep 17 00:00:00 2001 From: Hendrik Demolder Date: Wed, 7 Aug 2019 17:16:48 +0200 Subject: [PATCH 2/7] Remove other dependency to old redis version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 641674c3..715e8314 100644 --- a/setup.py +++ b/setup.py @@ -31,7 +31,7 @@ url='http://github.com/grokzen/redis-py-cluster', license='MIT', install_requires=[ - 'redis==2.10.6' + 'redis' ], keywords=[ 'redis', From 084337339eef4e731aea22633542e273b0094bd2 Mon Sep 17 00:00:00 2001 From: Hendrik Demolder Date: Wed, 7 Aug 2019 17:32:05 +0200 Subject: [PATCH 3/7] Set to latest version --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 7800f0fa..0f9e7a9c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -redis +redis==3.3.6 From 51d0c902e7102f8068decf01c226d80d0b777906 Mon Sep 17 00:00:00 2001 From: Hendrik Demolder Date: Wed, 7 Aug 2019 17:36:56 +0200 Subject: [PATCH 4/7] set version also in setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 715e8314..84ac86ae 100644 --- a/setup.py +++ b/setup.py @@ -31,7 +31,7 @@ url='http://github.com/grokzen/redis-py-cluster', license='MIT', install_requires=[ - 'redis' + 'redis==3.3.6' ], keywords=[ 'redis', From 86c1a115b5a1dd9592cea4e222e35002a3d32f5c Mon Sep 17 00:00:00 2001 From: Hendrik Demolder Date: Thu, 8 Aug 2019 14:27:18 +0200 Subject: [PATCH 5/7] Just get everything started again --- rediscluster/client.py | 17 ++++++++--------- rediscluster/nodemanager.py | 29 ++++++++--------------------- 2 files changed, 16 insertions(+), 30 deletions(-) diff --git a/rediscluster/client.py b/rediscluster/client.py index 49046dde..180eb2f2 100644 --- a/rediscluster/client.py +++ b/rediscluster/client.py @@ -35,8 +35,7 @@ # 3rd party imports from redis import StrictRedis from redis.client import list_or_args, parse_info -from redis.connection import Token -from redis._compat import iteritems, basestring, b, izip, nativestr, long +from redis._compat import iteritems, basestring, izip, nativestr, long from redis.exceptions import RedisError, ResponseError, TimeoutError, DataError, ConnectionError, BusyLoadingError @@ -535,7 +534,7 @@ def cluster_failover(self, node_id, option): Sends to specefied node """ assert option.upper() in ('FORCE', 'TAKEOVER') # TODO: change this option handling - return self.execute_command('CLUSTER FAILOVER', Token(option)) + return self.execute_command('CLUSTER FAILOVER', option) def cluster_info(self): """ @@ -586,7 +585,7 @@ def cluster_reset(self, node_id, soft=True): Sends to specefied node """ - return self.execute_command('CLUSTER RESET', Token('SOFT' if soft else 'HARD'), node_id=node_id) + return self.execute_command('CLUSTER RESET', 'SOFT' if soft else 'HARD', node_id=node_id) def cluster_reset_all_nodes(self, soft=True): """ @@ -600,7 +599,7 @@ def cluster_reset_all_nodes(self, soft=True): return [ self.execute_command( 'CLUSTER RESET', - Token('SOFT' if soft else 'HARD'), + 'SOFT' if soft else 'HARD', node_id=node['id'], ) for node in self.cluster_nodes() @@ -636,9 +635,9 @@ def cluster_setslot(self, node_id, slot_id, state, bind_to_node_id=None): Sends to specefied node """ if state.upper() in ('IMPORTING', 'MIGRATING', 'NODE') and node_id is not None: - return self.execute_command('CLUSTER SETSLOT', slot_id, Token(state), node_id) + return self.execute_command('CLUSTER SETSLOT', slot_id, state, node_id) elif state.upper() == 'STABLE': - return self.execute_command('CLUSTER SETSLOT', slot_id, Token('STABLE')) + return self.execute_command('CLUSTER SETSLOT', slot_id, 'STABLE') else: raise RedisError('Invalid slot state: {0}'.format(state)) @@ -694,9 +693,9 @@ def scan_iter(self, match=None, count=None): pieces = ['SCAN', cursors[node]] if match is not None: - pieces.extend([Token('MATCH'), match]) + pieces.extend(['MATCH', match]) if count is not None: - pieces.extend([Token('COUNT'), count]) + pieces.extend(['COUNT', count]) conn.send_command(*pieces) diff --git a/rediscluster/nodemanager.py b/rediscluster/nodemanager.py index b16877d1..442b9118 100644 --- a/rediscluster/nodemanager.py +++ b/rediscluster/nodemanager.py @@ -9,7 +9,8 @@ # 3rd party imports from redis import StrictRedis -from redis._compat import b, unicode, bytes, long, basestring +from redis._compat import unicode, long, basestring +from redis.connection import Encoder from redis import ConnectionError, TimeoutError, ResponseError @@ -37,34 +38,20 @@ def __init__(self, startup_nodes=None, reinitialize_steps=None, skip_full_covera self.reinitialize_steps = reinitialize_steps or 25 self._skip_full_coverage_check = skip_full_coverage_check self.nodemanager_follow_cluster = nodemanager_follow_cluster - + self.encoder = Encoder( + connection_kwargs.get('encoding', 'utf-8'), + connection_kwargs.get('encoding_errors', 'strict'), + connection_kwargs.get('decode_responses', False) + ) if not self.startup_nodes: raise RedisClusterException("No startup nodes provided") - def encode(self, value): - """ - Return a bytestring representation of the value. - This method is copied from Redis' connection.py:Connection.encode - """ - if isinstance(value, bytes): - return value - elif isinstance(value, (int, long)): - value = b(str(value)) - elif isinstance(value, float): - value = b(repr(value)) - elif not isinstance(value, basestring): - value = unicode(value) - if isinstance(value, unicode): - # The encoding should be configurable as in connection.py:Connection.encode - value = value.encode('utf-8') - return value - def keyslot(self, key): """ Calculate keyslot for a given key. Tuned for compatibility with python 2.7.x """ - k = self.encode(key) + k = self.encoder.encode(key) start = k.find(b"{") From a2bfb6777c4ab740dcc385404e870596aaa62d4a Mon Sep 17 00:00:00 2001 From: Hendrik Demolder Date: Mon, 12 Aug 2019 15:31:08 +0200 Subject: [PATCH 6/7] disable transaction check --- rediscluster/client.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rediscluster/client.py b/rediscluster/client.py index 180eb2f2..64036541 100644 --- a/rediscluster/client.py +++ b/rediscluster/client.py @@ -277,9 +277,9 @@ def pipeline(self, transaction=None, shard_hint=None): """ if shard_hint: raise RedisClusterException("shard_hint is deprecated in cluster mode") - - if transaction: - raise RedisClusterException("transaction is deprecated in cluster mode") + #Hendrik: Make sure that you use only pipelining and transactions on the same shard! + #if transaction: + # raise RedisClusterException("transaction is deprecated in cluster mode") return StrictClusterPipeline( connection_pool=self.connection_pool, From 766bfadc6f9f6b4656e1b0975e934afe281bf0f6 Mon Sep 17 00:00:00 2001 From: Hendrik Demolder Date: Mon, 12 Aug 2019 15:43:40 +0200 Subject: [PATCH 7/7] make sure RedisClient is also supporting pipelines --- rediscluster/client.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/rediscluster/client.py b/rediscluster/client.py index 64036541..b39dd827 100644 --- a/rediscluster/client.py +++ b/rediscluster/client.py @@ -1270,8 +1270,9 @@ def pipeline(self, transaction=True, shard_hint=None): if shard_hint: raise RedisClusterException("shard_hint is deprecated in cluster mode") - if transaction: - raise RedisClusterException("transaction is deprecated in cluster mode") + #Hendrik: Make sure that you use only pipelining and transactions on the same shard! + #if transaction: + # raise RedisClusterException("transaction is deprecated in cluster mode") return StrictClusterPipeline( connection_pool=self.connection_pool,