redis pub/sub fix

This commit is contained in:
tim
2025-05-06 22:27:14 -04:00
parent 7f4c301491
commit 008b6793d1
7 changed files with 68 additions and 27 deletions

10
io.js
View File

@@ -1,7 +1,7 @@
import {createServer} from "http";
import {Server} from "socket.io";
import { createAdapter } from "@socket.io/redis-adapter";
import {redis} from "./cache.js";
import {redis, redisSubscriber} from "./cache.js";
import {fileURLToPath} from "url";
import path from "path";
import express from "express";
@@ -29,12 +29,14 @@ app.set('views', path.join(__dirname, 'views')); // Set the views directory
app.use(express.static(path.join(__dirname, 'public')));
app.use(cors())
app.use((err, req, res, next) => {
console.error(err.stack);
res.status(500).send('Something went wrong!');
});
initSnapShare(app)
export const httpServer = createServer(app)
export const io = new Server(httpServer, socketIoOptions)
const pubClient = redis.duplicate();
await pubClient.connect()
const adapter = createAdapter(pubClient, redis, {/*key:'socket.io'*/})
const adapter = createAdapter(redis, redisSubscriber, {/*key:'socket.io'*/})
io.adapter(adapter)