diff --git a/README.md b/README.md index 582fc80928..90a34d1c60 100644 --- a/README.md +++ b/README.md @@ -203,6 +203,7 @@ That way the default is to try reconnecting until 24h passed. limits total amount of connection tries. Setting this to 1 will prevent any reconnect tries. * `auth_pass` *null*; If set, client will run redis auth command on connect. * `family` *IPv4*; You can force using IPv6 if you set the family to 'IPv6'. See Node.js [net](https://nodejs.org/api/net.html) or [dns](https://nodejs.org/api/dns.html) modules how to use the family type. +* `disable_resubscribing`: *false*; If set to `true`, a client won't resubscribe after disconnecting ```js var redis = require("redis"), diff --git a/changelog.md b/changelog.md index 762f35f489..1bf4e91bc7 100644 --- a/changelog.md +++ b/changelog.md @@ -1,6 +1,16 @@ Changelog ========= +## v.2.x.x - xx, 2015 + +Features + +- Added disable_resubscribing option to prevent a client from resubscribing after reconnecting (@BridgeAR) + +Bugfixes + +- + ## v2.1.0 - Oct 02, 2015 Features: @@ -14,7 +24,7 @@ Bugfixes: - Fix argument mutation while using the array notation with the multi constructor (@BridgeAR) - Fix multi.hmset key not being type converted if used with an object and key not being a string (@BridgeAR) - Fix parser errors not being catched properly (@BridgeAR) -- Fix a crash that could occur if a redis server does return the info command as usual #541 (@BridgeAR) +- Fix a crash that could occur if a redis server does not return the info command as usual #541 (@BridgeAR) - Explicitly passing undefined as a callback statement will work again. E.g. client.publish('channel', 'message', undefined); (@BridgeAR) ## v2.0.1 - Sep 24, 2015 @@ -27,7 +37,7 @@ Bugfixes: This is the biggest release that node_redis had since it was released in 2010. A long list of outstanding bugs has been fixed, so we are very happy to present you redis 2.0 and we highly recommend updating as soon as possible. -#What's new in 2.0 +# What's new in 2.0 - Implemented a "connection is broken" mode if no connection could be established - node_redis no longer throws under any circumstances, preventing it from terminating applications. diff --git a/index.js b/index.js index a0e17e6098..01b135907b 100644 --- a/index.js +++ b/index.js @@ -318,6 +318,9 @@ RedisClient.prototype.on_ready = function () { self.emit("ready"); } }; + if (this.options.disable_resubscribing) { + return; + } Object.keys(this.subscription_set).forEach(function (key) { var space_index = key.indexOf(" "); var parts = [key.slice(0, space_index), key.slice(space_index + 1)]; diff --git a/test/pubsub.spec.js b/test/pubsub.spec.js index 4cf801758d..d8c93ae9f6 100644 --- a/test/pubsub.spec.js +++ b/test/pubsub.spec.js @@ -26,20 +26,67 @@ describe("publish/subscribe", function () { pub.once("connect", function () { pub.flushdb(function () { pubConnected = true; + if (subConnected) { + done(); + } }); }); sub.once("error", done); sub.once("connect", function () { subConnected = true; + if (pubConnected) { + done(); + } + }); + }); + + describe('disable resubscribe', function () { + beforeEach(function (done) { + var pubConnected; + var subConnected; + + pub = redis.createClient(); + sub = redis.createClient({ + disable_resubscribing: false + }); + pub.once("error", done); + pub.once("connect", function () { + pubConnected = true; + if (subConnected) { + done(); + } + }); + + sub.once("error", done); + sub.once("connect", function () { + subConnected = true; + if (pubConnected) { + done(); + } + }); }); - var id = setInterval(function () { - if (pubConnected && subConnected) { - clearInterval(id); - return done(); - } - }, 50); + it('does not fire subscribe events after reconnecting', function (done) { + var a = false; + sub.on("subscribe", function (chnl, count) { + if (chnl === channel2) { + if (a) { + return done(new Error('Test failed')); + } + assert.equal(2, count); + sub.stream.destroy(); + } + }); + + sub.on('reconnecting', function() { + a = true; + }); + + sub.subscribe(channel, channel2); + + setTimeout(done, 250); + }); }); describe('subscribe', function () {