Gathering detailed insights and metrics for @socket.io/redis-adapter
Gathering detailed insights and metrics for @socket.io/redis-adapter
Gathering detailed insights and metrics for @socket.io/redis-adapter
Gathering detailed insights and metrics for @socket.io/redis-adapter
Adapter to enable broadcasting of events to multiple separate socket.io server nodes.
npm install @socket.io/redis-adapter
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
2,741 Stars
270 Commits
488 Forks
142 Watching
4 Branches
50 Contributors
Updated on 23 Nov 2024
Minified
Minified + Gzipped
TypeScript (100%)
Cumulative downloads
Total Downloads
Last day
-7.2%
38,316
Compared to previous day
Last week
2.5%
215,813
Compared to previous week
Last month
3.6%
912,708
Compared to previous month
Last year
36.2%
9,379,837
Compared to previous year
3
1
The @socket.io/redis-adapter
package allows broadcasting packets between multiple Socket.IO servers.
Table of contents
Feature | socket.io version | Support |
---|---|---|
Socket management | 4.0.0 | :white_check_mark: YES (since version 6.1.0 ) |
Inter-server communication | 4.1.0 | :white_check_mark: YES (since version 7.0.0 ) |
Broadcast with acknowledgements | 4.5.0 | :white_check_mark: YES (since version 7.2.0 ) |
Connection state recovery | 4.6.0 | :x: NO |
npm install @socket.io/redis-adapter
Redis Adapter version | Socket.IO server version |
---|---|
4.x | 1.x |
5.x | 2.x |
6.0.x | 3.x |
6.1.x | 4.x |
7.x and above | 4.3.1 and above |
redis
package1import { createClient } from "redis"; 2import { Server } from "socket.io"; 3import { createAdapter } from "@socket.io/redis-adapter"; 4 5const pubClient = createClient({ url: "redis://localhost:6379" }); 6const subClient = pubClient.duplicate(); 7 8await Promise.all([ 9 pubClient.connect(), 10 subClient.connect() 11]); 12 13const io = new Server({ 14 adapter: createAdapter(pubClient, subClient) 15}); 16 17io.listen(3000);
redis
package and a Redis cluster1import { createCluster } from "redis"; 2import { Server } from "socket.io"; 3import { createAdapter } from "@socket.io/redis-adapter"; 4 5const pubClient = createCluster({ 6 rootNodes: [ 7 { 8 url: "redis://localhost:7000", 9 }, 10 { 11 url: "redis://localhost:7001", 12 }, 13 { 14 url: "redis://localhost:7002", 15 }, 16 ], 17}); 18const subClient = pubClient.duplicate(); 19 20await Promise.all([ 21 pubClient.connect(), 22 subClient.connect() 23]); 24 25const io = new Server({ 26 adapter: createAdapter(pubClient, subClient) 27}); 28 29io.listen(3000);
ioredis
package1import { Redis } from "ioredis"; 2import { Server } from "socket.io"; 3import { createAdapter } from "@socket.io/redis-adapter"; 4 5const pubClient = new Redis(); 6const subClient = pubClient.duplicate(); 7 8const io = new Server({ 9 adapter: createAdapter(pubClient, subClient) 10}); 11 12io.listen(3000);
ioredis
package and a Redis cluster1import { Cluster } from "ioredis"; 2import { Server } from "socket.io"; 3import { createAdapter } from "@socket.io/redis-adapter"; 4 5const pubClient = new Cluster([ 6 { 7 host: "localhost", 8 port: 7000, 9 }, 10 { 11 host: "localhost", 12 port: 7001, 13 }, 14 { 15 host: "localhost", 16 port: 7002, 17 }, 18]); 19const subClient = pubClient.duplicate(); 20 21const io = new Server({ 22 adapter: createAdapter(pubClient, subClient) 23}); 24 25io.listen(3000);
Sharded Pub/Sub was introduced in Redis 7.0 in order to help scaling the usage of Pub/Sub in cluster mode.
Reference: https://redis.io/docs/interact/pubsub/#sharded-pubsub
A dedicated adapter can be created with the createShardedAdapter()
method:
1import { Server } from "socket.io"; 2import { createClient } from "redis"; 3import { createShardedAdapter } from "@socket.io/redis-adapter"; 4 5const pubClient = createClient({ host: "localhost", port: 6379 }); 6const subClient = pubClient.duplicate(); 7 8await Promise.all([ 9 pubClient.connect(), 10 subClient.connect() 11]); 12 13const io = new Server({ 14 adapter: createShardedAdapter(pubClient, subClient) 15}); 16 17io.listen(3000);
Minimum requirements:
redis@4.6.0
Note: it is not currently possible to use the sharded adapter with the ioredis
package and a Redis cluster (reference).
Name | Description | Default value |
---|---|---|
key | The prefix for the Redis Pub/Sub channels. | socket.io |
requestsTimeout | After this timeout the adapter will stop waiting from responses to request. | 5_000 |
publishOnSpecificResponseChannel | Whether to publish a response to the channel specific to the requesting node. | false |
parser | The parser to use for encoding and decoding messages sent to Redis. | - |
Name | Description | Default value |
---|---|---|
channelPrefix | The prefix for the Redis Pub/Sub channels. | socket.io |
subscriptionMode | The subscription mode impacts the number of Redis Pub/Sub channels used by the adapter. | dynamic |
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
GitHub workflow tokens follow principle of least privilege
Details
Reason
license file detected
Details
Reason
6 existing vulnerabilities detected
Details
Reason
0 commit(s) and 4 issue activity found in the last 90 days -- score normalized to 3
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
Found 8/28 approved changesets -- score normalized to 2
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More