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
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?
const io = new Server(http, {
// commenting this line out, i get my webserver response to http://localhost:3000
// with the line not commented out, my webserver response to http://localhost:3000 hangs forever
adapter: createStreamsAdapter(pubClient),
});
Full example:
import {logger} from '../logging/logger.js';
import express from 'express';
import {createServer} from 'node:http';
import {Server} from 'socket.io';
import {dirname, join} from 'node:path';
import {fileURLToPath} from 'node:url';
import {createClient} from 'redis';
import {getRedisConfig} from '../redis/redisConfig.js';
import {createAdapter as createStreamsAdapter} from '@socket.io/redis-streams-adapter';
export const startServer = async () => {
const port = process.env.PORT || 3000;
const app = express();
const __dirname = dirname(fileURLToPath(import.meta.url));
app.get('/', (req, res) => {
res.sendFile(join(__dirname, '/../../public', 'index.html'));
});
app.use(express.static('public'));
const http = createServer(app);
http.listen(port, () => {
console.log(`Server running on port ${port}`);
console.log(`http://localhost:${port}`);
});
const pubClient = createClient(getRedisConfig());
pubClient.on('error', (err) => logger.error('Pub Client Error', err));
pubClient.on('connect', () => console.log('🔄 Redis connecting...'));
pubClient.on('ready', () => console.log('✅ Redis ready!'));
pubClient.on('end', () => console.log('🔚 Redis connection ended'));
await pubClient.connect();
logger.info('Using Redis Streams Adapter');
const io = new Server(http, {
// commenting this line out, i get my webserver response to http://localhost:3000
// with the line not commented out, my webserver response to http://localhost:3000 hangs forever
adapter: createStreamsAdapter(pubClient),
});
io.on('connection', function (socket) {
console.log('Client connected to the WebSocket');
socket.on('disconnect', () => {
console.log('Client disconnected');
});
socket.on('chat message', function (msg) {
console.log('Received a chat message');
io.emit('chat message', msg);
});
});
logger.info('Finished creating server');
};
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
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