diff --git a/lib/ExpressRedisCache.js b/lib/ExpressRedisCache.js index 9cb05aa..9475787 100644 --- a/lib/ExpressRedisCache.js +++ b/lib/ExpressRedisCache.js @@ -85,17 +85,22 @@ module.exports = (function () { this.emit('error', error); }.bind(this)); - this.client.on('connect', function () { + function onConnect() { this.connected = true; this.emit('connected', { host: this.host, port: this.port }); this.emit('message', 'OK connected to redis://' + this.client.address); - }.bind(this)); + } + this.client.on('connect', onConnect.bind(this)); this.client.on('end', function () { this.connected = false; this.emit('disconnected', { host: this.host, port: this.port }); this.emit('message', 'Disconnected from redis://' + this.client.host + ':' + this.client.port); }.bind(this)); + + if ( !this.connected && this.client.connected ) { + onConnect.bind(this)(); + } } }