使用 node v16.16.0、redis-cli 7.0.0 和“redis”时:“^4.2.0”
下面出现这样的例外:
捕获异常:TypeError:侦听器不是函数异常 来源:uncaughtException[2022-07-18T07:39:30.386Z] process.on uncaughtException ERRORCODE 105199 TypeError:侦听器不是 功能 在 Function._RedisCommandsQueue_emitPubSubMessage (/mnt/c/Projects/konnectcore/app/sse/sse/node_modules/@redis/client/dist/lib/client/commands-queue.js:241:9) 在RedisCommandsQueue._RedisCommandsQueue_handlePubSubReply(/mnt/c/Projects/konnectcore/app/sse/sse/node_modules/@redis/client/dist/lib/client/commands-queue.js:283:100)
使用节点redis“redis”时工作正常:“^2.8.0”。
我遇到了类似的问题,我可能正在使用某种旧的方式来订阅和接收消息。像这样的东西:
sub.on('message', (channel, message) => {
redisClient.hSet('values', message, someFunction);
});
sub.subscribe('channel');
我希望您在redis客户端中使用正确的方式发布和订阅频道。以下是他们文档中的一个示例:
// This is how you create the client
import { createClient } from 'redis';
const client = createClient();
// This is the subscriber part
const subscriber = client.duplicate();
await subscriber.connect();
await subscriber.subscribe('channel', (message) => {
console.log(message); // 'message'
});
// This is an example of how to publish a message to the same channel
await publisher.publish('channel', 'message');
如果您想查看有关使用 node-redis 客户端发布和订阅消息的更多详细信息,请点击以下链接:https://github.com/redis/node-redis#pubsub