Skip to content

Shared PubSub compatiable issue with ioredis #499

Closed
@ngot

Description

@ngot

iosredis added the ssubscribe support https://github.com/luin/ioredis/pull/1690/files

but their API is ssubscribe rather than sSubscribe, same with the sPublish vs spublish.

TypeError: this.subClient.sSubscribe is not a function

I believe we might need to have the workaround like this

const isRedisV4 = typeof this.pubClient.pSubscribe === "function";
    if (isRedisV4) {
      this.redisListeners.set("psub", (msg, channel) => {
        this.onmessage(null, channel, msg);
      });

      this.redisListeners.set("sub", (msg, channel) => {
        this.onrequest(channel, msg);
      });

      this.subClient.pSubscribe(
        this.channel + "*",
        this.redisListeners.get("psub"),
        true
      );
      this.subClient.subscribe(
        [
          this.requestChannel,
          this.responseChannel,
          this.specificResponseChannel,
        ],
        this.redisListeners.get("sub"),
        true
      );
    } else {
      this.redisListeners.set("pmessageBuffer", this.onmessage.bind(this));
      this.redisListeners.set("messageBuffer", this.onrequest.bind(this));

      this.subClient.psubscribe(this.channel + "*");
      this.subClient.on(
        "pmessageBuffer",
        this.redisListeners.get("pmessageBuffer")
      );

      this.subClient.subscribe([
        this.requestChannel,
        this.responseChannel,
        this.specificResponseChannel,
      ]);
      this.subClient.on(
        "messageBuffer",
        this.redisListeners.get("messageBuffer")
      );
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions