Skip to content

TypeError: this.subClient.psubscribe is not a function #423

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
aekryz1993 opened this issue Oct 25, 2021 · 11 comments
Closed

TypeError: this.subClient.psubscribe is not a function #423

aekryz1993 opened this issue Oct 25, 2021 · 11 comments
Labels
enhancement New feature or request
Milestone

Comments

@aekryz1993
Copy link

aekryz1993 commented Oct 25, 2021

pubClient.duplicate() return object with a property function named pSubscribe (S is uppercase). and at /node_modules/@socket.io/redis-adapter/dist/index.js the property is named psubscribe (S is lowercase).

For now, The issue is fixed by adding property psubscribe (S is lowercase):

const { Server } = require("socket.io");
const { createAdapter } = require("@socket.io/redis-adapter");
const { createClient } = require("redis");

const io = new Server();

const pubClient = createClient({ host: "localhost", port: 6379 });

const subClient = pubClient.duplicate();
subClient.psubscribe = subClient.pSubscribe

Versions:

"redis": "^4.0.0-rc.1",
"@socket.io/redis-adapter": "^7.0.0",

The error was:

error: TypeError: this.subClient.psubscribe is not a function
          at new RedisAdapter (/node_modules/@socket.io/redis-adapter/dist/index.js:64:24)
          at new OurOwnRedisAdapter (/lib/websocket-adapter.js:39:5)
          at Namespace._initAdapter (/node_modules/socket.io/dist/namespace.js:40:24)
          at Server.adapter (/node_modules/socket.io/dist/index.js:133:17)
          at module.exports (/lib/websocket.js:27:6)
          at Server.<anonymous> (/server.js:25:16)
          at Object.onceWrapper (events.js:421:28)
          at Server.emit (events.js:315:20)
          at emitListeningNT (net.js:1352:10)
          at processTicksAndRejections (internal/process/task_queues.js:79:21)
@darrachequesne
Copy link
Member

Hi! I guess we could replace psubscribe by PSUBSCRIBE, but I wasn't able to find the way to pub/sub a buffer:

const { createClient } = require("redis");

(async () => {
  const client = createClient();
  await client.connect();

  const subscriber = client.duplicate();
  await subscriber.connect();

  await subscriber.subscribe("channel", (message, channel) => {
    console.log(message, channel);
  });

  client.publish("channel", "test"); // prints "test channel"
  client.publish("channel", Buffer.from([1,2,3])); // prints "��� channel" (buffer as string)

})();

The return_buffers option of v3 does not seem to be supported anymore. Does anyone have a clue?

@darrachequesne
Copy link
Member

An issue was opened here: redis/node-redis#1718

Note: we could also use base64 encoding, but it would be a backward incompatible change

@NarHakobyan
Copy link

Hi guys, as I see node-redis has merged the PR, so do you have plans to release a new version?

@darrachequesne
Copy link
Member

I'm working on this.

@NarHakobyan
Copy link

@darrachequesne thank you 🙏

@darrachequesne
Copy link
Member

Support for redis@4 was added in release 7.1.0: https://github.com/socketio/socket.io-redis-adapter/releases/tag/7.1.0

@darrachequesne darrachequesne added this to the 7.1.0 milestone Nov 30, 2021
@djaffer
Copy link

djaffer commented Dec 2, 2021

Please in the documentation add connect if it is explicitly required or the package doing when the client is passed.

@yanush
Copy link

yanush commented Dec 11, 2021

you added support for redis (v4) and broke the support for ioredis
"clientSub.PSUBSCRIBE is not a function" at new RedisAdapter (..../node_modules/@socket.io/redis-adapter/dist/index.js:76:24)
7.0.1 doesn't have that issue

@darrachequesne
Copy link
Member

@yanush that's weird, I was not able to reproduce, and it seems there is no PSUBSCRIBE (all uppercase) command in the codebase. Could you please check?

@yanush
Copy link

yanush commented Dec 13, 2021

@darrachequesne I think you are right. It might be some patched code I tried to fix the node-redis v4 support.
Sorry for the hassle.
Thanks!

@darrachequesne
Copy link
Member

@djaffer done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants