【发布时间】:2023-03-13 09:00:01
【问题描述】:
我在node.js 有这样的服务器:
socket.on('connection', function(client) {
const subscribe = redis.createClient(6379, '127.0.0.1')
subscribe.psubscribe('kitchen_*');
subscribe.on("pmessage", function(pattern, channel, message) {
client.emit(channel, message);
log('msg', "received from channel #" + channel + " : " + message);
});
});
在客户端我是这样的:
socket.on('kitchen_companyName', function (data) {
console.log('received a message: ', data);
});
现在我只想在客户端接收 kitchen_companyName 的消息,但即使公司名称是 kitchen_hello 我也收到了消息。我正在使用 pyredis 从 python 发布到 redis。
r = redis.StrictRedis(host='localhost', port=6379)
r.publish('kitchen_'+request.user.user_company, message)
【问题讨论】:
标签: python node.js redis socket.io