How to configure Redis clients when connecting to master-replica setup?

1.2k views Asked by At

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?

1

There are 1 answers

3
Efran Cobisi On BEST ANSWER

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.