Question

Sometimes my node-redis client take a long time to a initial connect to redis server.

I log .on('error'), .on('end'), .on('connect') and .on('ready') events here:

Redis:  storage#0 <localhost:6381> end
Redis: error storage#0 <localhost:6381> [Error: Redis connection to localhost:6381 failed - getaddrinfo ENOTFOUND]
/*... much of same errors, sometimes up to 5minutes ...*/
Redis: error storage#0 <localhost:6381> [Error: Redis connection to localhost:6381 failed - getaddrinfo ENOTFOUND]
Redis:  storage#0 <localhost:6381> connect
Redis:  storage#0 <localhost:6381> ready

While it happened I can normally connect to the redis-server using redis-cli.

Have somebody any ideas about reason of this?

Était-ce utile?

La solution

Error "[Error: Redis connection to localhost:6381 failed - getaddrinfo ENOTFOUND]" seems to point to an address resolution issue.

A simple proposal was therefore to use 127.0.0.1 instead of localhost to bypass the call to getaddrinfo, and the associated DNS query which can fail.

The result with 127.0.0.1 was slightly different: still an error, but the message was now ECONNREFUSED meaning that the remote Redis server was probably not listening to the provided port - or perhaps the connection timeout was set too low.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top