Skip to content

Commit 97db227

Browse files
pbihlerRuben Bridgewater
authored andcommitted
Fix for channel names with spaces. Fixes #691
Channel names with spaces were not properly resubscribed after a reconnection. Conflicts: index.js
1 parent b35a685 commit 97db227

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,8 @@ RedisClient.prototype.on_ready = function () {
308308
}
309309
};
310310
Object.keys(this.subscription_set).forEach(function (key) {
311-
var parts = key.split(" ");
311+
var space_index = key.indexOf(" ");
312+
var parts = [key.slice(0, space_index), key.slice(space_index + 1)];
312313
debug("Sending pub/sub on_ready " + parts[0] + ", " + parts[1]);
313314
callback_count++;
314315
self.send_command(parts[0] + "scribe", [parts[1]], callback);

test/pubsub.spec.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,22 @@ describe("publish/subscribe", function () {
4343
});
4444

4545
describe('subscribe', function () {
46-
it('fires a subscribe event for each channel subscribed to', function (done) {
46+
it('fires a subscribe event for each channel subscribed to even after reconnecting', function (done) {
47+
var a = false;
4748
sub.on("subscribe", function (chnl, count) {
4849
if (chnl === channel2) {
4950
assert.equal(2, count);
50-
return done();
51+
if (a) {
52+
return done();
53+
}
54+
sub.stream.destroy();
5155
}
5256
});
5357

58+
sub.on('reconnecting', function() {
59+
a = true;
60+
});
61+
5462
sub.subscribe(channel, channel2);
5563
});
5664

0 commit comments

Comments
 (0)