5

I am using Redis Cluster on 3 Linux servers (CentOS 7). I have standard configuration i.e. 6 nodes, 3 master instances, and 3 slave instances (one master have one slave) distributed on these 3 Linux servers. I am using this setup for my web application for data caching, HTTP response caching. My aim is to read primary and write secondary i.e. Read operation should not fail or delayed.

Now I would like to ask is it necessary to configure any load balancer before by 3 Linux servers so that my web application requests to Redis cluster instances can be distributed properly on these Redis servers? Or Redis cluster itself able to handle the load distribution?

If Yes, then please mention any reference link to configure the same. I have checked official documentation Redis Cluster but it does not specify anything regarding load balancer setup.

Ashish Shukla
  • 1,239
  • 12
  • 23

1 Answers1

3

If you're running Redis in "Cluster Mode" you don't need a load balancer. Your Redis client (assuming it's any good) should contact Redis for a list of which slots are on which nodes when your application starts up. It will hash keys locally (in your application) and send requests directly to the node which owns the slot for that key (which avoids the extra call to Redis which results in a MOVED response).

You should be able to configure your client to do reads on slave and writes on master - or to do both reads and writes on only masters. In addition to configuring your client, if you want to do reads on slaves, check out the READONLY command: https://redis.io/commands/readonly .

phonaputer
  • 1,485
  • 4
  • 9
  • I am using Redis stack exchange client in C# to connect to the Redis cluster. So does this handle the mentioned scenario i.e. connects to the specific node only to read data? – Ashish Shukla Jun 03 '20 at 04:54
  • I'm not a C# developer so I couldn't tell you. It should say in the documentation for the client if it supports the `READONLY` slaves in cluster mode. Or maybe there's an answer on SO in the C# tags? – phonaputer Jun 03 '20 at 06:44
  • I just reread your comment. Not considering `READONLY` slaves, if the client says it handles Redis Cluster then it should handle connecting to whichever node actually owns the data. Cluster Mode Redis will not allow reading a key from a node which doesn't own that key (it returns `MOVED` if something tries to access a key on the wrong node). So for a client to say it works with Redis Cluster it must handle connecting to the proper node for each key. Thus I would imagine that the client you mentioned handles this. I do not know if it handles `READONLY` slaves. – phonaputer Jun 03 '20 at 07:11
  • Is this `READONLY` available as a configuration parameter? Is this a one-time configuration? How to turn if off? – Kok How Teh Nov 09 '20 at 10:41
  • According to the docs it can be turned off with the READWRITE command: https://redis.io/commands/readwrite . Also I believe (but have not tested) READONLY is per connection: https://redis.io/topics/cluster-spec#scaling-reads-using-slave-nodes . From that doc: for each connection you open to Redis you must send a READONLY command if you want that connection to be able to read from slaves. – phonaputer Nov 13 '20 at 09:32