8

Has anyone encountered below error while connecting to standalone redis server using node js ioredis package?

Below is the error stack trace:

2018-08-16T10:52:18.351869060Z [ioredis] Unhandled error event: Error: connect ETIMEDOUT
2018-08-16T10:52:07.449457296Z at Timer.listOnTimeout (timers.js:207:5)
2018-08-16T10:52:07.449448499Z at tryOnTimeout (timers.js:237:5)
2018-08-16T10:52:07.449439722Z at ontimeout (timers.js:365:14)
2018-08-16T10:52:07.449430834Z at Socket._onTimeout (net.js:339:8)
2018-08-16T10:52:07.449421915Z at Socket.emit (events.js:185:7)
2018-08-16T10:52:07.449413002Z at emitNone (events.js:86:13)
2018-08-16T10:52:07.449403458Z at Socket.g (events.js:291:16)

This is occurring for instantiating only Standalone Redis object in node js. Below is the code I am using,

var publisher = new redis(redisPort, redisHost);

any solution would be highly appreciated.

Ankur Soni
  • 5,725
  • 5
  • 50
  • 81

4 Answers4

9

You can probably try increasing the timeout limit since ioredis has a default timeout value.

Normally we would have it set as,

new Redis({
  connectTimeout: 10000
})

In your case, since you have,

var publisher = new redis(redisPort, redisHost);

You will have to edit your code to pass the connectTimeout parameter to be passed accordingly.

Hope this helps.

David R
  • 14,711
  • 7
  • 54
  • 72
5

It's a bit late but can be helpful in the future for somebody else.

const redis = new Redis({
   port: <your_redis_port>,
   host: <your_redis_hostname>,
   connectTimeout: 10000
});
Sahil Verma
  • 131
  • 3
  • 12
3

I am using Redis client maintained by Heroku and for some strange reason the Redis credentials have been changed by Heroku, I have been facing the same issue until I double-check the old credentials and the one on Heroku and I realised they were no longer the same then copied the new one from Heroku and pasted it in my .env file and everything is working as expected now!!!

Shamxeed
  • 382
  • 4
  • 8
  • 1
    Yeah same thing happened to me. Weird. – TeemuK Jan 19 '22 at 14:02
  • 1
    If you happened to create the Redis client while you are initiating the project, this error would not occur as Heroku will automatically be updating the credentials for you. This error is a result of creating your project separately then later on you added the Redis client add-on. Hope my explanation is clear. By the way thanks for the upvote!! :)) – Shamxeed Jan 19 '22 at 16:53
0

Adding keepAlive helped me.

const redisClient = new Redis({
  host: CONFIG.REDIS_HOST,
  username: CONFIG.REDIS_USER,
  password: CONFIG.REDIS_PASSWORD,
  port: CONFIG.REDIS_PORT,
  lazyConnect: true,
  keepAlive: 1000,
});
Serhii Zharkov
  • 496
  • 5
  • 22