-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a note about multiple Pub/Sub channel listeners #2433
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! |
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 test
pass with this change (including linting)?