redis / node-redis

Redis Node.js client
https://redis.js.org/
MIT License
16.95k stars 1.89k forks source link

Elasticache Redis with cluster mode disabled but failover enabled #2326

Open cbazureau opened 2 years ago

cbazureau commented 2 years ago

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 :

configuration

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();

Questions :

Environment:

cbazureau commented 2 years ago

FYI i've switched to ioredis with the same configuration (2 connexions, one to write / one to read) and it works

af-andy commented 1 year ago

Anybody else run into this and find a solution?