Replies: 2 comments
-
|
@jimbglenn two things going on here: 1. upgrade to the older v0.2.x uses v0.3.0 fixes this by using npm install @socket.io/redis-streams-adapter@latest2. move engine.io hooks into the const http = createServer(app);
// create socket.io FIRST
const io = new Server(http, {
adapter: createStreamsAdapter(pubClient),
});
io.on('connection', function (socket) {
// ...
});
// THEN listen
http.listen(port, () => {
console.log(`Server running on port ${port}`);
});for reference, the regular const pubClient = createClient({ url: '...' });
const subClient = pubClient.duplicate();the streams adapter v0.3.0 handles this internally now via ref: redis-streams-adapter changelog | socket.io redis adapter docs | node-redis isolation pool issue |
Beta Was this translation helpful? Give feedback.
-
|
el problema tipico con redis-streams-adapter es que el servidor se queda colgado esperando la conexion a redis antes de arrancar. asegurate de que el adapter esta inicializado antes de pasar al listen: import { createClient } from "redis"
import { createAdapter } from "@socket.io/redis-streams-adapter"
const redisClient = createClient({ url: "redis://localhost:6379" })
await redisClient.connect() // esto es clave, esperar a que conecte
const io = new Server(http)
io.adapter(createAdapter(redisClient))
http.listen(3000) // solo escucha cuando ya esta todo listosi el cliente de redis no ha conectado antes de crear el adapter peta o se queda pillado. ponlo todo con async/await en un main() y llamas a listen al final |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Whenever I tried to add the redis-streams-adapter, my webserver stops responding.
I'm using redis-streams-adapter to use Valkey.
I assume I'm putting the adapter code in the right place.
Any guidance?
Full example:
Beta Was this translation helpful? Give feedback.
All reactions