我正在将Redis与node-redis lib一起使用,实现了PubSub,在其中我将发布者的消息从发布者发送到notification
频道,并且有一个订阅者正在收听此频道。订阅者完成订阅后,如何使用同一渠道获得发布者的响应?这可能吗,还是有必要创建一个新频道?
publisher.js
var redis = require("redis");
var publisher = redis.createClient(6379, "127.0.0.1");
publisher.publish("notification", "{ \"message\": \"Hello world from Asgardian!\" }", function () {
process.exit(0);
});
subscriber.js
var redis = require("redis");
var subscriber = redis.createClient(6379, "127.0.0.1");
subscriber.on("message", function (channel, message) {
console.log("Message: " + message + " on channel: " + channel + " is arrive!");
});
subscriber.subscribe("notification");