Skip to content
This repository was archived by the owner on Jan 9, 2024. It is now read-only.

Commit 6f1fb57

Browse files
committed
only send readonly to replicas once on new connections
1 parent 73f27ed commit 6f1fb57

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

rediscluster/client.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,6 @@ def _execute_command(self, *args, **kwargs):
578578

579579
redirect_addr = None
580580
asking = False
581-
is_read_replica = False
582581

583582
try_random_node = False
584583
slot = self._determine_slot(*args)
@@ -605,7 +604,6 @@ def _execute_command(self, *args, **kwargs):
605604
slot,
606605
self.read_from_replicas and (command in self.READ_COMMANDS)
607606
)
608-
is_read_replica = node['server_type'] == 'slave'
609607

610608
connection = self.connection_pool.get_connection_by_node(node)
611609

@@ -615,12 +613,6 @@ def _execute_command(self, *args, **kwargs):
615613
connection.send_command('ASKING')
616614
self.parse_response(connection, "ASKING", **kwargs)
617615
asking = False
618-
if is_read_replica:
619-
# Ask read replica to accept reads (see https://redis.io/commands/readonly)
620-
# TODO: do we need to handle errors from this response?
621-
connection.send_command('READONLY')
622-
self.parse_response(connection, 'READONLY', **kwargs)
623-
is_read_replica = False
624616

625617
connection.send_command(*args)
626618
return self.parse_response(connection, command, **kwargs)

rediscluster/connection.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,10 @@ def get_connection_by_node(self, node):
343343
connection = self._available_connections.get(node["name"], []).pop()
344344
except IndexError:
345345
connection = self.make_connection(node)
346+
if node["server_type"] == "slave":
347+
connection.send_command('READONLY')
348+
if nativestr(connection.read_response()) != 'OK':
349+
raise ConnectionError('READONLY command failed')
346350

347351
self._in_use_connections.setdefault(node["name"], set()).add(connection)
348352

0 commit comments

Comments
 (0)