Open
Description
When using this package with node-redis, I get the following error
node:internal/process/promises:289
triggerUncaughtException(err, true /* fromPromise */);
^
[ErrorReply: ERR unknown command 'psubscribe', with args beginning with: socket.io#/#*]
The only related issue I can find, is this one which describes switching to io-redis over node-redis when using elasticache for cluster mode. #484
This issue in node-redis says support was added: redis/node-redis#2065 but they don't really give any documention on how to use it.
Does this package support node-redis with Elasticache in AWS? I'm running Redis OSS cluster serverless. Thanks for the help
"socket.io": "^4.7.5",
"@socket.io/redis-adapter": "^8.3.0",
"@socket.io/redis-emitter": "^5.1.0",
"redis": "^4.7.0",
Here's a code snippet of my current socket implementation which does throws the error
const { Server } = require("socket.io");
const { createAdapter } = require("@socket.io/redis-adapter");
const { Emitter } = require("@socket.io/redis-emitter");
const { createClient } = require("redis");
const redis = require('../../configs/redis');
const env = process.env.NODE_ENV || 'local';
const host = redis[env].host || '127.0.0.1';
const port = redis[env].port || 6379;
let io = null;
let emitter = null;
function startServer(server) {
const pubClient = createClient({
url: `rediss://${host}:${port}`, // rediss:// is the secure version of redis://
});
const subClient = pubClient.duplicate();
const tasks = [
pubClient.connect(), subClient.connect()
];
Promise.all(tasks).then(() => {
emitter = new Emitter(pubClient);
const serverOptions = {
adapter: createAdapter(pubClient, subClient, {
key: adapterKey,
requestsTimeout: 10000
}),
connectionStateRecovery: {
maxDisconnectionDuration: 2 * 60 * 1000, // the backup duration of the sessions and the packets
skipMiddlewares: true, // whether to skip middlewares upon successful recovery
},
cors: {
origin: [
'http://localhost:8080',
'http://localhost:3000',
'http://localhost',
]
}
};
io = new Server(server, serverOptions);
io.on('connection', (socket) => {
console.log(`WebSocket connection established: socket.id ${socket.id} for ${ioKey}`);
socket.on('error', function (err) {
console.error('Socket error', err);
});
});
io.on('socketMessage', (data) => {
console.log(`${ioKey} received socketMessage`); // Logs all clusters that received the message
});
io.on('error', (err) => {
console.error('WebSocket server error', err);
});
io.on('close', () => {
console.error('WebSocket server closed');
});
io.engine.on("connection_error", (err) => {
console.error('WebSocket connection error', err); // See https://socket.io/docs/v4/troubleshooting-connection-issues
});
}).catch((err) => {
console.error('FATAL: Could not start Socket.io server with redis adapter', err);
});
}
Thanks for the help
Metadata
Metadata
Assignees
Labels
No labels