Connect to master and slave in a replicated Redis cluster

I am setting up a simple cluster of the 1st Red-Slave cluster (low write, high read rate). How to set this up is well documented on the Redis website, however there is no information (or I missed it) about how clients (Node.js servers in my case) process the cluster. Should my servers open 2 Redis connections: one for Master (writes) and one for load balancing Slave for reading? Does the Redis driver handle this automatically and send reads to slaves and write to the master?

+6
source share
2 answers

The only approach I found is to use the thunk-redis library . This library supports connecting to a Redis master-slave without setting up a cluster or using a sentinel.

You simply add multiple IP addresses to the client:

const client = redis.createClient(['127.0.0.1:6379', '127.0.0.1:6380'], {onlyMaster: false}); 
+1
source

You do not need to specifically connect to a specific instance, each instance in the redis cluster has cluster information. Therefore, even if you connect to one host, your client will connect to any instance in the cluster. Therefore, if you try to update a key that is present in different wizards (except the one you connected), the redis client will take care of this using the redirection provided by the server.

To answer the second question, you can enable reading from the slave READONLY command

0
source

Source: https://habr.com/ru/post/1258717/


All Articles