From 11db346e733db5b7de8d8a44f1b45bfaf1cd75e8 Mon Sep 17 00:00:00 2001 From: roam Date: Wed, 19 Dec 2012 15:04:07 +0800 Subject: [PATCH] Fixed an unexpected exception bug when reconnecting in pub/sub mode if selected_db is not null RedisClient might enter pub/sub mode after at least one SELECT command issued. When reconnecting, the SELECT command is issued after restoring pub_sub_command to true, which causes an exception. --- index.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/index.js b/index.js index 2dc86a9659..2c2ae23c7f 100644 --- a/index.js +++ b/index.js @@ -282,7 +282,12 @@ RedisClient.prototype.on_ready = function () { // magically restore any modal commands from a previous connection if (this.selected_db !== null) { + // this trick works if and only if the following send_command + // never goes into the offline queue + var pub_sub_mode = this.pub_sub_mode; + this.pub_sub_mode = false; this.send_command('select', [this.selected_db]); + this.pub_sub_mode = pub_sub_mode; } if (this.pub_sub_mode === true) { // only emit "ready" when all subscriptions were made again