Add a note about multiple Pub/Sub channel listeners#2433
Add a note about multiple Pub/Sub channel listeners#2433leibale merged 2 commits intoredis:masterfrom
Conversation
Clarify that multiple subscriptions create multiple listeners.
|
@jamesw6811 Thanks for contributing, but... that's not true... when you // `SUBSCRIBE a`
await client.subscribe('a', message => {
console.log(message);
});
// no command will be executed on the server
// but the callback will be added to the callback set
await client.subscribe('a', message => {
console.log(message);
});
await anotherClient.publish('a', 'b');
// `client` will get the message once over the network, and then call both callbacks with the message. |
|
redis-cli stops accepting new commands after one SUBSCRIBE. I didn't realize this wasn't also the behavior of the api. It might confuse others, so I still think it's a helpful addition. Redis docs: |
|
Maybe I'm not understanding the redis source correctly, but my reading is that the subscriptions are based on a dictionary of clients, so if the same client tried to subscribe twice it would not duplicate: Am I missing something? I'm newer to Redis so please excuse all the things I'm probably getting wrong... |
|
@jamesw6811 You can use |
|
@guyroyse :) |
Exactly. Expecting either functionality is reasonable, but that documentation one-liner would have saved me some time. Thought it might save some others' time too. Thanks for the telnet tip! |
* Add multiple listener language to pub/sub docks Clarify that multiple subscriptions create multiple listeners. * Update pub-sub.md --------- Co-authored-by: Leibale Eidelman <me@leibale.com>
Clarify that multiple subscriptions create multiple listeners.
Description
This change informs the developer that multiple subscriptions will create multiple listeners. This is important because redis-cli SUBSCRIBE commands do not behave this way, so it may be counter-intuitive.
I personally spent some time debugging my code and my misunderstanding of this was the root cause.
Checklist
npm testpass with this change (including linting)?