1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-07 13:22:56 +03:00

Add disable_resubscribingg option. Fixes #472

This commit is contained in:
Ruben Bridgewater
2015-10-02 23:28:59 +02:00
parent 088b3f6996
commit e8d9858e29
4 changed files with 69 additions and 8 deletions

View File

@@ -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. 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. * `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. * `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 ```js
var redis = require("redis"), var redis = require("redis"),

View File

@@ -1,6 +1,16 @@
Changelog 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 ## v2.1.0 - Oct 02, 2015
Features: Features:
@@ -14,7 +24,7 @@ Bugfixes:
- Fix argument mutation while using the array notation with the multi constructor (@BridgeAR) - 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 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 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) - Explicitly passing undefined as a callback statement will work again. E.g. client.publish('channel', 'message', undefined); (@BridgeAR)
## v2.0.1 - Sep 24, 2015 ## v2.0.1 - Sep 24, 2015

View File

@@ -318,6 +318,9 @@ RedisClient.prototype.on_ready = function () {
self.emit("ready"); self.emit("ready");
} }
}; };
if (this.options.disable_resubscribing) {
return;
}
Object.keys(this.subscription_set).forEach(function (key) { Object.keys(this.subscription_set).forEach(function (key) {
var space_index = key.indexOf(" "); var space_index = key.indexOf(" ");
var parts = [key.slice(0, space_index), key.slice(space_index + 1)]; var parts = [key.slice(0, space_index), key.slice(space_index + 1)];

View File

@@ -26,20 +26,67 @@ describe("publish/subscribe", function () {
pub.once("connect", function () { pub.once("connect", function () {
pub.flushdb(function () { pub.flushdb(function () {
pubConnected = true; pubConnected = true;
if (subConnected) {
done();
}
}); });
}); });
sub.once("error", done); sub.once("error", done);
sub.once("connect", function () { sub.once("connect", function () {
subConnected = true; subConnected = true;
if (pubConnected) {
done();
}
});
}); });
var id = setInterval(function () { describe('disable resubscribe', function () {
if (pubConnected && subConnected) { beforeEach(function (done) {
clearInterval(id); var pubConnected;
return done(); var subConnected;
pub = redis.createClient();
sub = redis.createClient({
disable_resubscribing: false
});
pub.once("error", done);
pub.once("connect", function () {
pubConnected = true;
if (subConnected) {
done();
} }
}, 50); });
sub.once("error", done);
sub.once("connect", function () {
subConnected = true;
if (pubConnected) {
done();
}
});
});
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 () { describe('subscribe', function () {