-
Notifications
You must be signed in to change notification settings - Fork 315
readonly mode not execute command on slave node #339
Comments
@ididid8 I did some digging into this issue, what i figured out is that there is two different connectionpools implemented that is controlled and activated by two different flags. What it seems like is that the flag you are using right now
|
The two different connection pools will get a makeover in 3.0.0 |
I found this bug today as well, figured out I need to set |
@Grokzen There's another bug. Currently, the pipeline will never work on replicas, https://github.com/Grokzen/redis-py-cluster/blob/master/rediscluster/pipeline.py#L197. |
import random
from rediscluster.connection import ClusterWithReadReplicasConnectionPool
from rediscluster import RedisCluster
class ClusterWithOnlyReadReplicasConnectionPool(ClusterWithReadReplicasConnectionPool):
def get_node_by_slot(self, slot, read_command=False):
nodes_in_slot = self.nodes.slots[slot]
# return slave node as possible
if read_command:
try:
random_index = random.randrange(1, len(nodes_in_slot))
return nodes_in_slot[random_index]
except KeyError:
pass
return nodes_in_slot[0]
startup_nodes = [{"host": "127.0.0.1", "port": "7000"}]
pool = ClusterWithOnlyReadReplicasConnectionPool(
startup_nodes=startup_nodes,
decode_responses=True,
)
rc = RedisCluster(
connection_pool=pool,
read_from_replicas=True,
)
for i in range(0, 10):
print(rc.get('foo')) Use this code read from slave nodes |
I set readonly_mode=True to test the readonly mode. And print the node which realy execute command. But whether readonly_mode is True or False the node server_type is all master.
I print the node in client.py to get node info.
The print is :
I consider is because of the partial get node.
The text was updated successfully, but these errors were encountered: