Node JS Redis Client Connection Retry

Tamil picture Tamil · Mar 30, 2012 · Viewed 12.5k times · Source

Currently I'm using https://github.com/mranney/node_redis as my node redis client.

client.retry_delay is set to 250ms default.

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.

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.

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?

Answer

Linus Thiel picture Linus Thiel · Mar 30, 2012

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);
    }
}