From dcbb87dff7cf2426268bb50dd5423216d9f1b091 Mon Sep 17 00:00:00 2001 From: Orion Henry Date: Mon, 27 Sep 2010 17:11:12 -0700 Subject: [PATCH] fix bug not allowing you to quit while in subscribe mode - added test --- index.js | 5 ++--- test.js | 8 ++++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 015944b..c091f17 100644 --- a/index.js +++ b/index.js @@ -564,11 +564,10 @@ RedisClient.prototype.send_command = function () { } this.subscriptions = true; } else { - if (this.subscriptions === true) { - throw new Error("Connection in pub/sub mode, only pub/sub commands may be used"); - } if (command === "QUIT") { this.closing = true; + } else if (this.subscriptions === true) { + throw new Error("Connection in pub/sub mode, only pub/sub commands may be used"); } this.command_queue.push(command_obj); } diff --git a/test.js b/test.js index 840c7b2..22d9b07 100644 --- a/test.js +++ b/test.js @@ -2,6 +2,7 @@ var redis = require("./index"), client = redis.createClient(), client2 = redis.createClient(), + client3 = redis.createClient(), assert = require("assert"), sys = require('sys'), tests = {}, iterations = 10000; @@ -238,6 +239,13 @@ tests.SUBSCRIBE = function () { client1.subscribe("chan1", "chan2"); }; +tests.SUBSCRIBE_QUIT = function () { + var name = "SUBSCRIBE_QUIT"; + client3.on("end", function() { next(name) }); + client3.on("subscribe", function (channel, count) { client3.quit(); }); + client3.subscribe("chan3"); +} + tests.EXISTS = function () { var name = "EXISTS"; client.del("foo", "foo2", require_number_any(name));