2

I have a Redis setup with 1 master and 2 replicas - so totally 3 nodes. Given that writes can happen only via master node while reads can happen via all 3 nodes, how do I configure the clients?

Can I pass all nodes IP in the IP list and the client will take care of connecting to the right node by itself? Or do the clients need to be configured separately for reads and writes?

Ankit Sahay
  • 1,710
  • 8
  • 14

1 Answers1

1

It depends on the specific client you are using; some clients automatically split read-only / write commands based on the client-connection configuration, while others allow to specify the preferred replication target at the command or invocation level.

For example, ioredis automatically handles that through the scaleReads configuration option, while StackExchange.Redis allows to handle that through the CommandFlags enum at the command invocation level: you should really check the documentation of the specific Redis client you want to use.

Finally, redis-cli does not split read-only / write commands; it can connect (via the -c option) to a Redis Cluster and follow slot redirections automatically - but the connection will always happen against a master node, with no read/write splitting.

Efran Cobisi
  • 6,138
  • 22
  • 22
  • Thank you for your answer. I tried looking for the similar configuration in redis-py client but couldn't find it. Can you please help me get that piece of documentation? – Ankit Sahay Dec 27 '22 at 13:02
  • You are welcome! As far as I can see, redis-py supports read/write command splitting only when connecting to a Redis cluster - and not to a non-cluster Redis replication topology. In the former case, you can connect using the [`RedisCluster` class](https://redis.readthedocs.io/en/stable/connections.html#cluster-client) and specify the default splitting behavior through the `read_from_replicas` option and choose the desired behavior while executing each command through the `target_nodes` kwarg. – Efran Cobisi Dec 27 '22 at 19:00
  • So what do we do in the non-cluster replication topology? If we want read-write split - do the clients have to specify replica nodes when trying to read and master nodes when trying to write? – Ankit Sahay Dec 28 '22 at 17:10