1

I have facing this issue redis connection timeout in my node application.

I have tried this code,

new Redis({
  connectTimeout: 10000
})

But was of no use it didn't help me with the code

[ioredis] Unhandled error event: Error: connect ETIMEDOUT
    at Socket.<anonymous> (/code/node_modules/ioredis/lib/redis.js:291:21)
    at Object.onceWrapper (events.js:313:30)
    at emitNone (events.js:106:13)
    at Socket.emit (events.js:208:7)
    at Socket._onTimeout (net.js:407:8)
    at ontimeout (timers.js:475:11)
    at tryOnTimeout (timers.js:310:5)
    at Timer.listOnTimeout (timers.js:270:5)
David R
  • 14,711
  • 7
  • 54
  • 72
Jakka rohith
  • 475
  • 2
  • 7
  • 15
  • Are you able to access your redis instance locally? run `redis-cli ping` if you don't get back `PONG`, then you don't have redis running on your local machine, if you're connecting through a different port or a remote host, you'd also need to pass that to your initializer – oreoluwa May 23 '19 at 12:04
  • Actually I am using redis container and my container is Up and running – Jakka rohith May 23 '19 at 12:19
  • Possibly this is an answer: https://stackoverflow.com/questions/51875870/ioredis-unhandled-error-event-error-connect-etimedout – Pavel Kovalev Sep 09 '20 at 16:09

1 Answers1

1

When you say container, I'd assume you mean docker containers. If you're using the docker network, I believe you can always change the host to the name of your docker container within the network. If you're using docker-compose, here's an idea of how that may be done:

version: '3'
services:
  app:
   image: app_image
   depends_on:
    - redis
   networks:
    - app_network
  redis:
   image: redis
   networks:
    - app_network
networks:
  app_network: {}

So in your app, you'd then do

redis = new Redis({
  host: 'redis://redis'
})
oreoluwa
  • 5,553
  • 2
  • 20
  • 27