Registry / messaging / socket.io-redis-adapter

socket.io-redis-adapter

JSON →
library8.4.6jsnpmunverified

Redis-based adapter for Socket.IO that enables broadcasting events between multiple Socket.IO server instances via Redis Pub/Sub. Version 8.4.6 (stable), maintained by the Socket.IO team. Ships TypeScript types. Requires socket.io-adapter ^2.4.0 peer dependency. Supports CommonJS, ES modules, and TypeScript. Key differentiator: uses two separate Redis clients (pub/sub) for reliability; supports both standard and sharded Pub/Sub (Redis 7.0+). Migration from legacy socket.io-redis package requires API changes.

npm install socket.io-redis-adapter
INSTALL
IMPORT
SIG · SOCKET.IO-REDIS-AD
S
socket.io-redis-adapter
messagingjavascriptv8.4.6
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

createAdapter
✓ import { createAdapter } from 'socket.io-redis-adapter'
✗ const createAdapter = require('socket.io-redis'); // wrong package name
Package renamed from 'socket.io-redis' to 'socket.io-redis-adapter' in v6. Always use the new name.
RedisAdapter
✓ import { RedisAdapter } from 'socket.io-redis-adapter'
✗ import RedisAdapter from 'socket.io-redis-adapter'; // default import does not exist
Only named exports are provided. No default export.

Create a Socket.IO server with Redis adapter using two Redis clients (pub/sub). Must call connect() for each client (redis@4+).

import { Server } from 'socket.io'; import { createClient } from 'redis'; import { createAdapter } from 'socket.io-redis-adapter'; const io = new Server(); const pubClient = createClient({ url: process.env.REDIS_URL ?? 'redis://localhost:6379' }); const subClient = pubClient.duplicate(); Promise.all([ pubClient.connect(), subClient.connect() ]).then(() => { io.adapter(createAdapter(pubClient, subClient)); io.listen(3000); console.log('Socket.IO server with Redis adapter listening on port 3000'); });
Debug
Known issues
breakingPackage renamed from 'socket.io-redis' to 'socket.io-redis-adapter' in version 6.0.0. Old package deprecated.
fix
Replace require('socket.io-redis') with require('socket.io-redis-adapter') and update imports to named export createAdapter.
affects: <6.0.0
breakingredis@4+ requires explicit connect() calls. Not calling pubClient.connect()/subClient.connect() causes 'start' event to fail silently.
fix
Add await pubClient.connect() and await subClient.connect() before calling io.adapter().
affects: >=8.0.0
gotchaUsing the same Redis client instance for both pub and sub leads to message deduplication issues and potential deadlocks.
fix
Always use pubClient.duplicate() to create a separate sub client.
affects: >=1.0.0
deprecatedUsage with ioredis client is deprecated. Prefer 'redis' package (node-redis) v4+.
fix
Switch from ioredis to redis package. If using ioredis, ensure compatibility via custom adapter options.
affects: >=8.0.0
Errors
Common errors & fixes
Error: Cannot find module 'socket.io-redis'
Package renamed to 'socket.io-redis-adapter' but code still imports the old name.
fix
npm uninstall socket.io-redis && npm install socket.io-redis-adapter && change imports to 'socket.io-redis-adapter'
TypeError: pubClient.connect is not a function
Using redis@3 (no need for connect()) or ioredis but calling connect() like redis@4. Or using redis@4 and not importing createClient correctly.
fix
Check Redis client version. For redis@3: don't call connect(). For redis@4: import { createClient } from 'redis' and call client.connect(). For ioredis: use new Redis() and don't call connect().
Upgrade
Version history
8.4.6latest on npm
Audit
Dependencies
socket.io-adapteroptionalPeer dependency required for adapter interface
redisoptionalApplication must install a Redis client (e.g., ioredis or node-redis) to create pub/sub clients
Agent activity
16 hits · last 30 days
node
14
Amazon
1
OpenAI (training)
1
Resources
socket.io-redis-adapter — npm install socket.io-redis-adapter · libregistry