node-redis
node-redis copied to clipboard
Elasticache Redis with cluster mode disabled but failover enabled
We are facing a READONLY You can't write against a read only replica
error (followed by a Socket closed unexpectedly
error) when we want to write on our AWS ElastiCache Redis cluster (Cluster mode off) when multi-AZ and failover are enabled.
On redis server side :
On client (nodejs) side :
2 persistant connexions, one for the "master" (called Primary Endpoint on AWS), one for the "replica" (called Reader Endpoint on AWS)
const ACTIVATE_READ = true;
const writeClient = redis.createClient({ url: '<master-endpoint>', ... });
const readClient = ACTIVATE_READ ? redis.createClient({ url: '<master-endpoint>', ... }) : writeClient;
await writeClient.connect();
if (ACTIVATE_READ) await readClient.connect();
await readClient.get('foo');
await writeClient.set('foo', 'bar', { EX: 30 }); // Fails here if ACTIVATE_READ is true
await readClient.get('foo');
await writeClient.quit();
if (ACTIVATE_READ) await readClient.quit();
- No issue with the "replica" connexion when multi-AZ and failover are enabled or disabled
- No issue with the "master" connexion when multi-AZ and failover are disabled or when "master" connexion is used as the only connexion (ACTIVATE_READ = false)
- When multi-AZ and failover are enable, node-redis seems to go to the wrong client (using the readClient instead of the writeClient).
Questions :
- Does node-redis support the AWS failover mode, or did i miss something on the configuration ?
- In case of failover, is there an internal mechanism in node-redis that ensure to switch to the good node.
Environment:
- Node.js Version: 16 and 18 (at least)
- Redis Server Version: AWS ElastiCache Redis 6.2.4 with Multi-AZ + failover enable (2 nodes)
- Node Redis Version: 4.5.0
- Platform: docker alpine-node
FYI i've switched to ioredis with the same configuration (2 connexions, one to write / one to read) and it works
Anybody else run into this and find a solution?