redis-namespaced-pubsub
v4.0.1
Published
Allows you to broadcast and subscribe messages prefixed by a namespace. The message names are separated by columns into namespaces. An example message name could be "u:employee:joe:gotpaid". Any subscriber subscribed to any of "u:*", "u:employee:*", "u:e
Downloads
4
Readme
redis-namespaced-pubsub
Allows you to broadcast and subscribe messages prefixed by a namespace. The message names are separated by columns into namespaces. An example message name could be "u:employee:joe:gotpaid". Any subscriber subscribed to any of "u:", "u:employee:", "u:employee:joe:*" or "u:employee:joe:gotpaid" would receive such message.
Usage
// all the messages will be prefixed by u:namespace1:
var redis = require("redis-namespaced-pubsub")({namespace: "u:namespace1:"});
subscriber = new redis.Subscriber(["routes:*", "deliveries:*"]);
publisher = new redis.Publisher();
var route = {};
subscriber.on("update", function(eventName, data) {
data.should.eql(route);
});
setTimeout(function() {
publisher.publish("routes:123456:patch", route);
}, 300);
// alternatively
subscriber = new updates.Subscriber(["routes:*", "deliveries:*"], function(eventName, data) {
data.should.eql(route);
});
See tests for more examples.