Skip to content

Commit e8d9858

Browse files
author
Ruben Bridgewater
committed
Add disable_resubscribingg option. Fixes #472
1 parent 088b3f6 commit e8d9858

File tree

4 files changed

+69
-8
lines changed

4 files changed

+69
-8
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ That way the default is to try reconnecting until 24h passed.
203203
limits total amount of connection tries. Setting this to 1 will prevent any reconnect tries.
204204
* `auth_pass` *null*; If set, client will run redis auth command on connect.
205205
* `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.
206+
* `disable_resubscribing`: *false*; If set to `true`, a client won't resubscribe after disconnecting
206207

207208
```js
208209
var redis = require("redis"),

changelog.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
Changelog
22
=========
33

4+
## v.2.x.x - xx, 2015
5+
6+
Features
7+
8+
- Added disable_resubscribing option to prevent a client from resubscribing after reconnecting (@BridgeAR)
9+
10+
Bugfixes
11+
12+
-
13+
414
## v2.1.0 - Oct 02, 2015
515

616
Features:
@@ -14,7 +24,7 @@ Bugfixes:
1424
- Fix argument mutation while using the array notation with the multi constructor (@BridgeAR)
1525
- Fix multi.hmset key not being type converted if used with an object and key not being a string (@BridgeAR)
1626
- Fix parser errors not being catched properly (@BridgeAR)
17-
- Fix a crash that could occur if a redis server does return the info command as usual #541 (@BridgeAR)
27+
- Fix a crash that could occur if a redis server does not return the info command as usual #541 (@BridgeAR)
1828
- Explicitly passing undefined as a callback statement will work again. E.g. client.publish('channel', 'message', undefined); (@BridgeAR)
1929

2030
## v2.0.1 - Sep 24, 2015
@@ -27,7 +37,7 @@ Bugfixes:
2737

2838
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.
2939

30-
#What's new in 2.0
40+
# What's new in 2.0
3141

3242
- Implemented a "connection is broken" mode if no connection could be established
3343
- node_redis no longer throws under any circumstances, preventing it from terminating applications.

index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,9 @@ RedisClient.prototype.on_ready = function () {
318318
self.emit("ready");
319319
}
320320
};
321+
if (this.options.disable_resubscribing) {
322+
return;
323+
}
321324
Object.keys(this.subscription_set).forEach(function (key) {
322325
var space_index = key.indexOf(" ");
323326
var parts = [key.slice(0, space_index), key.slice(space_index + 1)];

test/pubsub.spec.js

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,67 @@ describe("publish/subscribe", function () {
2626
pub.once("connect", function () {
2727
pub.flushdb(function () {
2828
pubConnected = true;
29+
if (subConnected) {
30+
done();
31+
}
2932
});
3033
});
3134

3235
sub.once("error", done);
3336
sub.once("connect", function () {
3437
subConnected = true;
38+
if (pubConnected) {
39+
done();
40+
}
3541
});
42+
});
3643

37-
var id = setInterval(function () {
38-
if (pubConnected && subConnected) {
39-
clearInterval(id);
40-
return done();
41-
}
42-
}, 50);
44+
describe('disable resubscribe', function () {
45+
beforeEach(function (done) {
46+
var pubConnected;
47+
var subConnected;
48+
49+
pub = redis.createClient();
50+
sub = redis.createClient({
51+
disable_resubscribing: false
52+
});
53+
pub.once("error", done);
54+
pub.once("connect", function () {
55+
pubConnected = true;
56+
if (subConnected) {
57+
done();
58+
}
59+
});
60+
61+
sub.once("error", done);
62+
sub.once("connect", function () {
63+
subConnected = true;
64+
if (pubConnected) {
65+
done();
66+
}
67+
});
68+
});
69+
70+
it('does not fire subscribe events after reconnecting', function (done) {
71+
var a = false;
72+
sub.on("subscribe", function (chnl, count) {
73+
if (chnl === channel2) {
74+
if (a) {
75+
return done(new Error('Test failed'));
76+
}
77+
assert.equal(2, count);
78+
sub.stream.destroy();
79+
}
80+
});
81+
82+
sub.on('reconnecting', function() {
83+
a = true;
84+
});
85+
86+
sub.subscribe(channel, channel2);
87+
88+
setTimeout(done, 250);
89+
});
4390
});
4491

4592
describe('subscribe', function () {

0 commit comments

Comments
 (0)