I donβt know what your design is, but you can subscribe with one redis client on several channels (after you subscribe with a client, you can only subscribe to another channel or unsubscribe in this connection: http://redis.io / commands / subscribe ), because after receiving the message you have the full information that this message is associated with. You can then distribute this message to all interested customers.
This helped me a bit, because I could put the message type in the channel name, and then dynamically select the action for each message from a small function instead of generating a separate subscription for each channel with separate logic.
Inside my node.js server, I only have 2 redis clients:
- simple client for all standard actions -
lpush , sadd , etc. - subscribe client - which listens for messages on subscription channels, these messages are distributed to all sessions (stored as sets for each type of channel) using the first redis client.
source share