在windows上使用redis创建客户端时出现问题

wbrvyc0a  于 2022-10-31  发布在  Redis
关注(0)|答案(1)|浏览(175)

运行代码时出现以下错误:
客户端关闭错误:客户端在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"
);

我该怎么解决呢?

ct3nt3jp

ct3nt3jp1#

这是因为redis版本中出现问题。使用:npm i redis@3.1.2版本

相关问题