Reputation: 662
I am using Redis as a Pub/Sub client in a Node.js application. I bind a subscriber to a channel pattern like thus:
client.psubscribe("events.*.new", (event) => console.log("NEW EVENT", event));
Then, I send a message on a specific channel this way:
client.publish("events.123.new", '{"some": "data"}');
In my terminal, I get the following output:
NEW EVENT null
My question is 2-fold:
null
?events.*.new
, it does not appear that I can know if a message was sent on channel events.123.new
or on events.456.new
. Is passing this information within the payload the only way to access it in listeners?Thanks in advance!
Upvotes: 0
Views: 1158
Reputation: 13532
Try this:
client.psubscribe("events.*.new");
client.on('pmessage', function (pattern, channel, message) {
console.log(pattern, channel, message);
});
client.publish("events.123.new", '{"some": "data"}');
The callback to psubscribe just returns error in the first argument if there is an error. You can find more info here
Upvotes: 1