How to reconnect redis connection?

I have simple example:

var redis = require('redis'),
client = redis.createClient();

var test = function() {
    client.brpop('log', 0, function(err, reply) {
        if (err != null ) {
            console.log(err);
        }    else {
            .... parse log string ....
        }
        test();
    });
}

test();

How to reconnect redis connection after restart redis server ?

The Redis client automatically reconnects. Just make sure you handle the "error" event from the client. Otherwise, this code is where the process begins.

this.emit("error", new Error(message));
// "error" events get turned into exceptions if they aren't listened for.  If the user handled this error
// then we should try to reconnect.
this.connection_gone("error");

Next, the .connection_gone() method runs on the client.

Notice that you can also listen to a "reconnecting" event to be notified when this happens.