Node JS Redis client reconnection

I am currently using as my node redis client.


set to 250ms by default.

I tried to connect to redis and when the connection was successful I manually stopped the redis server to see if client.retry_delay was working. But I haven't seen it work.

The following log messages are logged on events ready

and end

on redisClients created with 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  '' '6379'
[2012-03-30 15:16:33.886] [FATAL] Development - Connection Terminated to  '' '6379'


I have not yet seen the message "Successful message" [ready event was not fired] when the server came back in real time

Am I missing something? When will the repeat constant be used? Is there a work around to find if the redis server shows up after crashing with node?


source to share

2 answers

I cannot reproduce this. Could you try this code, stop the 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);




Adding to the answer above. Small change. The callback must be the name of the method and not execute the method itself. Something like below:

function redisCallbackHandler(message){
    console.log("Redis:"+ message);

var redis = require("redis");
var redisclient = redis.createClient();
redisclient.on('connect', redisCallbackHandler);
redisclient.on('ready', redisCallbackHandler);
redisclient.on('reconnecting', redisCallbackHandler);
redisclient.on('error', redisCallbackHandler);
redisclient.on('end', redisCallbackHandler);




All Articles