You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have written the following test code based on the documentation https://socket.io/docs/v4/redis-adapter/ and https://github.com/redis/node-redis/blob/master/docs/clustering.md.
importexpressfrom"express";importhttpfrom"http";import{ServerasSocketServer}from"socket.io";import{createAdapter}from"@socket.io/redis-adapter";import{createCluster}from"redis";constapp=express();constserver=http.createServer(app);constsio=newSocketServer(server);constpub=createCluster({rootNodes: [{url: "redis://192.168.64.1:6379",password: "password"},{url: "redis://192.168.64.2:6379",password: "password"},{url: "redis://192.168.64.3:6379",password: "password"},],});constsub=pub.duplicate();pub.on("error",(err)=>{console.log(`[err] PUB redis cluster: ${err}`);thrownewError("redis cluster error");});sub.on("error",(err)=>{console.log(`[err] SUB redis cluster: ${err}`);thrownewError("redis cluster error");});awaitpub.connect();awaitsub.connect();sio.adapter(createAdapter(pub,sub));sio.on("connection",(socket)=>{console.log(`hello: ${socket.id}`);socket.on("disconnect",()=>{console.log(`goodbye: ${socket.id}`);});socket.onAny((evt,data)=>{console.log(`from: ${socket.id}`,`- [${evt}]: ${data}`);});});app.get("/ping",(req,res)=>{res.send("pong");return;});server.listen(5139,()=>{console.log("server is listen on: 5139");});
But when I run this code, I get a TypeError:
TypeError: this.subClient.psubscribe is not a function
at new RedisAdapter (/path/to/project/node_modules/@socket.io/redis-adapter/dist/index.js:88:28)
at new <anonymous> (/path/to/project/node_modules/@socket.io/redis-adapter/dist/index.js:48:16)
at Namespace._initAdapter (/path/to/project/node_modules/socket.io/dist/namespace.js:93:24)
at Server.adapter (/path/to/project/node_modules/socket.io/dist/index.js:166:17)
at initServer (file:///path/to/project/src/server.js:35:7)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Node.js v18.13.0
I have tested this cluster pubsub with redis-cli and everything works fine when using redis-cli -c.
When I don't use createCluster and switch to use createClient everything works fine.
Hello, I'm using the following versions of socket.io and redis, with Node.js v18.13.0
I have written the following test code based on the documentation
https://socket.io/docs/v4/redis-adapter/
andhttps://github.com/redis/node-redis/blob/master/docs/clustering.md
.But when I run this code, I get a TypeError:
I have tested this cluster pubsub with redis-cli and everything works fine when using
redis-cli -c
.When I don't use
createCluster
and switch to use createClient everything works fine.When I run this code, everything looks ok.
This is very strange, can anyone help me?
The text was updated successfully, but these errors were encountered: