【发布时间】:2013-08-20 10:00:16
【问题描述】:
有时我的 node-redis 客户端需要很长时间才能初始连接到 redis 服务器。
我在这里记录 .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-server。
有人对此原因有任何想法吗?
【问题讨论】:
-
我不知道原因,但是您可能希望使用 127.0.0.1 来连接而不是 localhost,这样您就可以避免调用可能失败的 DNS。
-
:( 没有改变:
Redis: error storage#0 <127.0.0.1:6381> [Error: Redis connection to 127.0.0.1:6381 failed - connect ECONNREFUSED] -
嗯,错误代码是不同的......也许,您定义了过于激进的连接超时?它是连接时的选项之一(以毫秒为单位)。
-
一周过去了,我没有再收到这个错误)我相信我得到 ECONNREFUSED 因为 redis-server 无法访问。万分感谢。我之前不知道 localhost 解析会失败。
-
@DidierSpezia,您好,我查看并标记了我的问题,您可以发表您的第一条评论作为答案吗?它对我有帮助...
标签: node.js redis node-redis