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

Fix reading from replicas in pipelined commands #471

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions rediscluster/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,6 @@ def _execute_command(self, *args, **kwargs):

redirect_addr = None
asking = False
is_read_replica = False

try_random_node = False
slot = self._determine_slot(*args)
Expand Down Expand Up @@ -610,7 +609,6 @@ def _execute_command(self, *args, **kwargs):
slot,
self.read_from_replicas and (command in READ_COMMANDS)
)
is_read_replica = node['server_type'] == 'slave'

connection = self.connection_pool.get_connection_by_node(node)

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

connection.send_command(*args)
return self.parse_response(connection, command, **kwargs)
Expand Down
6 changes: 4 additions & 2 deletions rediscluster/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ def make_connection(self, node):

self._created_connections_per_node.setdefault(node['name'], 0)
self._created_connections_per_node[node['name']] += 1
connection = self.connection_class(host=node["host"], port=node["port"], **self.connection_kwargs)
readonly = node["server_type"] == "slave"
connection = self.connection_class(host=node["host"], port=node["port"], readonly=readonly, **self.connection_kwargs)

# Must store node in the connection to make it easier to track
connection.node = node
Expand Down Expand Up @@ -472,7 +473,8 @@ def reset(self):

def make_connection(self, node):
""" Create a new connection """
connection = self.connection_class(host=node["host"], port=node["port"], **self.connection_kwargs)
readonly = node["server_type"] == "slave"
connection = self.connection_class(host=node["host"], port=node["port"], readonly=readonly, **self.connection_kwargs)
self._connections.append(connection)
connection.node = node
return connection
Expand Down