Skip to content

Commit 94914ae

Browse files
author
Fran Garcia
committed
When read_from_replicas is enabled also read from master
1 parent df35f03 commit 94914ae

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

baseplate/clients/redis_cluster.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,14 @@ class ClusterWithReadReplicasBlockingConnectionPool(rediscluster.ClusterBlocking
2121
def get_node_by_slot(self, slot: int, read_command: bool = False) -> Dict[str, Any]:
2222
"""
2323
Get a node from the slot.
24-
If the command is a read command we'll try to return a random replica.
24+
If the command is a read command we'll try to return a random node.
2525
If there are no replicas or this isn't a read command we'll return the primary.
2626
"""
27-
primary, *replicas = self.nodes.slots[slot]
27+
if read_command:
28+
return random.choice(self.nodes.slots[slot])
2829

29-
if replicas and read_command:
30-
return random.choice(replicas)
31-
32-
# Either this isn't a read command or there aren't any replicas
33-
return primary
30+
# This isn't a read command, so return the primary
31+
return self.nodes.slots[slot]
3432

3533

3634
def cluster_pool_from_config(

0 commit comments

Comments
 (0)