From c687d2e4fd83eaf414439f83f3c9414c309eeb3a Mon Sep 17 00:00:00 2001 From: Iain Proctor Date: Tue, 8 Jul 2014 21:36:23 +0000 Subject: [PATCH] Make a new stream on reconnect --- index.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 13964983e0..1420179b12 100644 --- a/index.js +++ b/index.js @@ -81,6 +81,14 @@ function RedisClient(stream, options) { this.old_state = null; + this.install_stream_listeners(); + + events.EventEmitter.call(this); +} +util.inherits(RedisClient, events.EventEmitter); +exports.RedisClient = RedisClient; + +RedisClient.prototype.install_stream_listeners = function() { var self = this; this.stream.on("connect", function () { @@ -107,11 +115,7 @@ function RedisClient(stream, options) { self.should_buffer = false; self.emit("drain"); }); - - events.EventEmitter.call(this); -} -util.inherits(RedisClient, events.EventEmitter); -exports.RedisClient = RedisClient; +}; RedisClient.prototype.initialize_retry_vars = function () { this.retry_timer = null; @@ -520,7 +524,8 @@ RedisClient.prototype.connection_gone = function (why) { return; } - self.stream.connect(self.port, self.host); + self.stream = net.createConnection(self.port, self.host); + self.install_stream_listeners(); self.retry_timer = null; }, this.retry_delay); };