node.jsredisamazon-elasticachenode-redis

How do I configure my Redis client to use read replicas with cluster mode disabled?


I am using node-redis and AWS Elasticache with cluster mode disabled. I have 1 primary node and two replica nodes.

My replica nodes are not serving reads at all. This can be seen in the metrics tab of Elasticache, and is abundantly clear.

Redis documentation states that the READONLY command can be used to start reading from the replica nodes. The only mention of this functionality in node-redis is within their client configuration documentation, using the readonly flag (defaults to false). This is what is used to open new connections.

Our server currently maintains a single Redis connection, and uses that to issue all reads and writes. Is this documentation suggesting that I should open a new connection (create a client) before every command and set this readonly flag based on if my command is a read or a write? I feel like I should be able to keep a connection open and specify readonly on a per command basis to avoid constantly opening and closing connections.

What is the best way to interact with Redis if I can only set readonly at the connection level?


Solution

  • readonly command works for Redis Cluster, not standalone Redis. So it cannot solve your problem.

    Instead, you can create two connections: one for write (connecting to master, and the other for read (connecting to one of the replica).