运行代码时出现以下错误:
客户端关闭错误:客户端在Commander中关闭。
const redis = require("redis");
const CHANNELS = { TEST: "TEST" };
class Pubsub {
constructor() {
this.publisher = redis.createClient();
this.subscriber = redis.createClient();
this.subscriber.subscribe(CHANNELS.TEST);
this.subscriber.on("message", (channel, message) => {
this.handleMessage(channel, message);
});
}
handleMessage(channel, message) {
console.log(`message recieved. channel: ${channel}. message: ${message}`);
}
}
const testPubsub = new Pubsub();
testPubsub.publisher.publish(
CHANNELS.TEST,
"this is a message that published"
);
我该怎么解决呢?
1条答案
按热度按时间ct3nt3jp1#
这是因为redis版本中出现问题。使用:npm i redis@3.1.2版本