Node-redis非常长的初始连接

有时我的node-redis客户端需要很长时间才能初始连接到redis服务器。

我在这里login.on('error'),.on('end'),.on('connect')和.on('ready')事件:

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 

当发生这种情况时,我通常可以使用redis-cli连接到redis服务器。

有没有人有关于这个原因的任何想法?

错误“[错误:Redis连接到本地主机:6381失败 – getaddrinfo ENOTFOUND]”似乎指向一个地址parsing问题。

因此,一个简单的提议是使用127.0.0.1而不是本地主机绕过对getaddrinfo的调用以及可能失败的关联DNS查询。

127.0.0.1的结果稍有不同:仍是错误,但是现在的消息是ECONNREFUSED,这意味着远程Redis服务器可能不在监听提供的端口 – 或者连接超时设置得太低。