PubSub 上的节点 Redis 回调
Node Redis Callback on PubSub
为什么我在 Node Redis 中使用 PubSub 模式设计不能有回调?
例如:
server.publish("someChanel", someData, function(response) {
// response should come back from client
});
client.on('message', function(channel, data, callback) {
// Do stuff with data
// Return data to callback
callback(someNewData);
});
这显然失败了,因为 callback
没有定义。
redis连接会发出事件,所以当你注册client.on('message'
每次有消息时,function(channel, data)
就会触发。在该函数内,您可以做任何事情,包括调用不同的函数。
例如
function YourCallBackFn (err, data) {
// do something with data
}
server.publish("someChanel", someData, function(response) {
// response should come back from client
});
client.on('message', function(channel, data) {
// Do stuff with data
// Return data to callback
YourCallBackFn(null, data);
});
为什么我在 Node Redis 中使用 PubSub 模式设计不能有回调?
例如:
server.publish("someChanel", someData, function(response) {
// response should come back from client
});
client.on('message', function(channel, data, callback) {
// Do stuff with data
// Return data to callback
callback(someNewData);
});
这显然失败了,因为 callback
没有定义。
redis连接会发出事件,所以当你注册client.on('message'
每次有消息时,function(channel, data)
就会触发。在该函数内,您可以做任何事情,包括调用不同的函数。
例如
function YourCallBackFn (err, data) {
// do something with data
}
server.publish("someChanel", someData, function(response) {
// response should come back from client
});
client.on('message', function(channel, data) {
// Do stuff with data
// Return data to callback
YourCallBackFn(null, data);
});