Skip to content

Commit 50f1663

Browse files
committed
Merge pull request #1017 from NodeRedis/pubsub
Fix pub sub mode Fixes #603 Fixes #577 Fixes #137
2 parents 5294917 + 7a5a4aa commit 50f1663

9 files changed

+517
-167
lines changed

README.md

+19-19
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ client.get("foo_rand000000000000", function (err, reply) {
233233
client.get(new Buffer("foo_rand000000000000"), function (err, reply) {
234234
console.log(reply.toString()); // Will print `<Buffer 4f 4b>`
235235
});
236-
client.end();
236+
client.quit();
237237
```
238238

239239
retry_strategy example
@@ -302,7 +302,7 @@ client.get("foo_rand000000000000", function (err, reply) {
302302
});
303303
```
304304

305-
`client.end()` without the flush parameter should NOT be used in production!
305+
`client.end()` without the flush parameter set to true should NOT be used in production!
306306

307307
## client.unref()
308308

@@ -377,34 +377,34 @@ client connections, subscribes to a channel on one of them, and publishes to tha
377377
channel on the other:
378378

379379
```js
380-
var redis = require("redis"),
381-
client1 = redis.createClient(), client2 = redis.createClient(),
382-
msg_count = 0;
380+
var redis = require("redis");
381+
var sub = redis.createClient(), pub = redis.createClient();
382+
var msg_count = 0;
383383

384-
client1.on("subscribe", function (channel, count) {
385-
client2.publish("a nice channel", "I am sending a message.");
386-
client2.publish("a nice channel", "I am sending a second message.");
387-
client2.publish("a nice channel", "I am sending my last message.");
384+
sub.on("subscribe", function (channel, count) {
385+
pub.publish("a nice channel", "I am sending a message.");
386+
pub.publish("a nice channel", "I am sending a second message.");
387+
pub.publish("a nice channel", "I am sending my last message.");
388388
});
389389

390-
client1.on("message", function (channel, message) {
391-
console.log("client1 channel " + channel + ": " + message);
390+
sub.on("message", function (channel, message) {
391+
console.log("sub channel " + channel + ": " + message);
392392
msg_count += 1;
393393
if (msg_count === 3) {
394-
client1.unsubscribe();
395-
client1.end();
396-
client2.end();
394+
sub.unsubscribe();
395+
sub.quit();
396+
pub.quit();
397397
}
398398
});
399399

400-
client1.subscribe("a nice channel");
400+
sub.subscribe("a nice channel");
401401
```
402402

403403
When a client issues a `SUBSCRIBE` or `PSUBSCRIBE`, that connection is put into a "subscriber" mode.
404-
At that point, only commands that modify the subscription set are valid. When the subscription
404+
At that point, only commands that modify the subscription set are valid and quit (and depending on the redis version ping as well). When the subscription
405405
set is empty, the connection is put back into regular mode.
406406

407-
If you need to send regular commands to Redis while in subscriber mode, just open another connection.
407+
If you need to send regular commands to Redis while in subscriber mode, just open another connection with a new client (hint: use `client.duplicate()`).
408408

409409
## Subscriber Events
410410

@@ -413,13 +413,13 @@ If a client has subscriptions active, it may emit these events:
413413
### "message" (channel, message)
414414

415415
Client will emit `message` for every message received that matches an active subscription.
416-
Listeners are passed the channel name as `channel` and the message Buffer as `message`.
416+
Listeners are passed the channel name as `channel` and the message as `message`.
417417

418418
### "pmessage" (pattern, channel, message)
419419

420420
Client will emit `pmessage` for every message received that matches an active subscription pattern.
421421
Listeners are passed the original pattern used with `PSUBSCRIBE` as `pattern`, the sending channel
422-
name as `channel`, and the message Buffer as `message`.
422+
name as `channel`, and the message as `message`.
423423

424424
### "subscribe" (channel, count)
425425

changelog.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,21 @@ Changelog
55

66
Features
77

8-
- Monitor now works together with the offline queue
8+
- Monitor and pub sub mode now work together with the offline queue
99
- All commands that were send after a connection loss are now going to be send after reconnecting
1010
- Activating monitor mode does now work together with arbitrary commands including pub sub mode
11+
- Pub sub mode is completly rewritten and all known issues fixed
1112

1213
Bugfixes
1314

1415
- Fixed calling monitor command while other commands are still running
1516
- Fixed monitor and pub sub mode not working together
1617
- Fixed monitor mode not working in combination with the offline queue
18+
- Fixed pub sub mode not working in combination with the offline queue
19+
- Fixed pub sub mode resubscribing not working with non utf8 buffer channels
20+
- Fixed pub sub mode crashing if calling unsubscribe / subscribe in various combinations
21+
- Fixed pub sub mode emitting unsubscribe even if no channels were unsubscribed
22+
- Fixed pub sub mode emitting a message without a message published
1723

1824
## v.2.5.3 - 21 Mar, 2016
1925

0 commit comments

Comments
 (0)