Node JS Redis 客户端连接重试 [英] Node JS Redis Client Connection Retry
问题描述
目前我使用 https://github.com/mranney/node_redis 作为我的节点redis 客户端.
Currently I'm using https://github.com/mranney/node_redis as my node redis client.
client.retry_delay
默认设置为 250 毫秒.
client.retry_delay
is set to 250ms default.
我尝试连接到 redis,一旦连接成功,我手动停止了 redis 服务器以查看 client.retry_delay
是否有效.但我没有看到它起作用.
I tried connecting to redis and once connection was successful, I manually stopped the redis server to see whether client.retry_delay
works. But I didn't see it working.
以下日志消息记录在 ready
&使用 createClient
创建的 redisClient 上的 end
事件:
The following log messages are logged on ready
& end
events on redisClients created using createClient
:
[2012-03-30 15:13:05.498] [INFO] Development - Node Application is running on port 8090
[2012-03-30 15:13:08.507] [INFO] Development - Connection Successfully Established to '127.0.0.1' '6379'
[2012-03-30 15:16:33.886] [FATAL] Development - Connection Terminated to '127.0.0.1' '6379'
当服务器重新上线时,我没有再次看到成功消息[未触发就绪事件].
I didn't see Success message again [ready event was not fired] when the server came back live.
我错过了什么吗?什么时候使用重试常量?是否有解决方法来确定节点发生故障后 Redis 服务器是否已启动?
Am I missing something? When will be the retry constant used? Is there a work around to find whether a redis server has come up after a failure from node?
推荐答案
我无法重现.你可以试试这个代码,停止你的redis服务器,并检查日志输出吗?
I can't reproduce this. Could you try this code, stop your redis server, and check the log output?
var client = require('redis').createClient();
client.on('connect' , log('connect'));
client.on('ready' , log('ready'));
client.on('reconnecting', log('reconnecting'));
client.on('error' , log('error'));
client.on('end' , log('end'));
function log(type) {
return function() {
console.log(type, arguments);
}
}
这篇关于Node JS Redis 客户端连接重试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!