7

I'm setting up a simple 1 Master - N Slaves Redis cluster (low write round, high read count). How to set this up is well documented on the Redis website, however, there is no information (or I missed it) about how the clients (Node.js servers in my case) handle the cluster. Do my servers need to have 2 Redis connections opened: one for the Master (writes) and one towards a Slave load-balancer for reads? Does the Redis driver handle this automatically and send reads to slaves and writes to the Master?

Nepoxx
  • 4,849
  • 5
  • 42
  • 61
  • 1
    It depends on the driver you used. Redis has no specification on how client should access master and slaves. I suggest you to check the documentation of that driver. Also add a new tag for this post, e.g. `node-redis` (if this is the driver you used) – for_stack Oct 25 '16 at 05:12
  • @for_stack Thanks, I think that's a valid answer in of itself. – Nepoxx Oct 25 '16 at 15:40

2 Answers2

1

The only approach I found was using thunk-redis library. This library supports connecting to Redis master-slave without having a cluster configured or using a sentinel.

You just simply add multiple IP addresses to the client:

const client = redis.createClient(['127.0.0.1:6379', '127.0.0.1:6380'], {onlyMaster: false});
Oresztesz
  • 2,294
  • 1
  • 15
  • 26
  • Does that autodetect which Redis host is the master and which are slaves, and target all writes to the master and allow reads to be split? I was hoping to see a client which allows read commands to take an extra parameter which allows them to be forced onto the master (where immediate integrity is required) or to be split onto slaves (where eventual consistency is acceptable). – rstaveley Dec 05 '19 at 08:11
  • Based on what I've seen from the library, I would say that it's not so sophisticated. For instance, I had to implement master reconnection myself. The documentation is not so descriptive and not saying anything about these scenarios either. – Oresztesz Dec 06 '19 at 06:50
0

You don't need to specifically connect to particular instance, every instance in redis cluster has information of cluster. So even if you connect to one master, your client would to be connect to any instance in the cluster. So if you try to update a key present in different master(other than the one you connected), redis client takes care of it by using the redirection provided by the server.

To answer your second question, you can enable reads from slave by READONLY command