Attach Redis Adapter to Socket.IO

Update src/config/socket.js to initialize the Redis adapter.

The createAdapter() function receives the publisher and subscriber clients.

The resulting adapter is configured through the Socket.IO server's adapter option.

Updated src/config/socket.js
import { Server } from 'socket.io';
import { createAdapter } from '@socket.io/redis-adapter';
import { pubClient, subClient } from './redis.js';

export function initializeSocket(httpServer) {
  const io = new Server(httpServer, {
    adapter: createAdapter(pubClient, subClient)
  });

  return io;
}

Configures Socket.IO to use Redis Pub/Sub for cross-instance broadcasting instead of relying only on its default in-memory adapter.

Key Takeaways
  • The adapter is configured during Socket.IO initialization.

  • Redis publisher and subscriber clients are shared with the adapter.

  • All instances must use compatible adapter configuration.