node.jsredis

Find out when ioredis connection has been established


I'm using ioredis module.

var Redis = require('ioredis');
var redis = new Redis();

On doing new Redis() a connection is established to the redis server, how can I find out when this connection established? some callback perhaps?


Solution

  • You can listen for the connect event:

    redis.on('connect', function () { /* do something */ });
    

    You can also use the connect(callback) method:

    redis.connect(function () { /* Do your stuff */ });
    

    The latter also returns a promise if you prefer that.