ioredis
ioredis copied to clipboard
Unhandled error event: Error: getaddrinfo ENOTFOUND - AWS ElasticCache
Hey guys, did anyone have some issue like that to connect in the AWS ElasticCache in the ECS Container?
[ioredis] Unhandled error event: Error: getaddrinfo ENOTFOUND cursobeta-dev-elasticache-redis.ilg7lv.ng.0001.use1.cache.amazonaws.com
Looks like permision, right?
const pubClient = new Redis({ host: process.env.AWS_REDIS_HOST, port: 6379 });
Try connecting using the redis:// protocol instead:
const pubClient = new Redis(`redis://${process.env.AWS_REDIS_HOST}:6379`)
Just FYI, this works for me if I use add those options.
const pubRedisClient = new Redis(
parseRedisCredentials(process.env.REDIS_CONNECTION ?? 'redis://localhost:6379', {
lazyConnect: true,
connectTimeout: 15000,
retryStrategy: (times) => Math.min(times * 30, 1000),
reconnectOnError(error) {
const targetErrors = [/READONLY/, /ETIMEDOUT/];
logger.warn(`Redis connection error: ${error.message}`, error);
return targetErrors.some((targetError) => targetError.test(error.message));
},
}),
);
Try setting family: 6
; for some reason ioredis defaults to family: 4
and AWS may be using (only) IPv6. Note I had the same issue on fly.io.
@richiejp thank you!!! This helped me out 😄
I'm having the same problem connecting to an IPV6 Redis instance.
Error: connect ETIMEDOUT
at Socket.<anonymous> (/.../node_modules/ioredis/built/Redis.js:170:41)
at Object.onceWrapper (node:events:509:28)
at Socket.emit (node:events:390:28)
at Socket._onTimeout (node:net:486:8)
at listOnTimeout (node:internal/timers:557:17)
at processTimers (node:internal/timers:500:7) {
errorno: 'ETIMEDOUT',
code: 'ETIMEDOUT',
syscall: 'connect'
}
I thought this was a bug on fastify-redis
plugin, which I opened an issue about 169. But while testing fastify-redis
code to submit a fix, I noticed that I can only connect to IPV6 when using localhost
.
This made me test ioredis
directly to see if I could connect to my cluster.
Insanely, I still can't connect using the family: 6
option. Which leads me to use another Redis cluster that doesn't use IPV6.
Is there any chance for the pull request https://github.com/luin/ioredis/pull/1607 to be merged?
thanks @richiejp ! In my case fly io was also working only with family: 6.
For anyone who may concern, you can also append the family=6
option to the redis URL (if you can't add family:6
). For example, it should changeredis://domain:6379
to redis://domain:6379/?family=6
.
Nothing helps :(
@Warxcell same :') been trying to figure this out for the past couple of days. were you able to figure it out?
Any update here ? I am stuck in the same problem
// Connect to 127.0.0.1:6380, db 4, using password "authpassword": new Redis('redis://:[email protected]:6380/4')
https://ioredis.readthedocs.io/en/stable/README/
a yo.
Try connecting using the redis:// protocol instead:
const pubClient = new Redis(`redis://${process.env.AWS_REDIS_HOST}:6379`)
Adding redis:// protocol worked for me. It works fine on local machine as well as on ec2 server
I had the same error, I solved with this replacing the host name with corresponding ip address
redis://<user_name>:nslookup host_name
Any updates on this?
Hope it helps someone here. We were facing a similar issue and this answer from Stack Overflow worked well for us - https://stackoverflow.com/questions/76409668/how-to-connect-to-amazon-memorydb-for-redis-from-node-running-in-ec2-ecs