{"id":14978143,"url":"https://github.com/socketio/socket.io-redis-streams-adapter","last_synced_at":"2025-04-05T08:04:01.562Z","repository":{"id":151660669,"uuid":"624460151","full_name":"socketio/socket.io-redis-streams-adapter","owner":"socketio","description":"The Socket.IO adapter based on Redis Streams, allowing to broadcast events between several Socket.IO servers.","archived":false,"fork":false,"pushed_at":"2025-01-28T14:45:20.000Z","size":115,"stargazers_count":32,"open_issues_count":6,"forks_count":16,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-03-29T04:05:35.377Z","etag":null,"topics":["redis","socket-io","websocket"],"latest_commit_sha":null,"homepage":"https://socket.io/docs/v4/redis-streams-adapter/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/socketio.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-04-06T14:12:23.000Z","updated_at":"2025-03-26T06:11:25.000Z","dependencies_parsed_at":"2024-02-27T23:41:52.683Z","dependency_job_id":"f91a9c50-cc5f-4f72-95e9-34566a06f9d0","html_url":"https://github.com/socketio/socket.io-redis-streams-adapter","commit_stats":{"total_commits":26,"total_committers":4,"mean_commits":6.5,"dds":"0.11538461538461542","last_synced_commit":"71ed4e4450ce0e59dd99e9d8c60e4e62bc8b15e0"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/socketio%2Fsocket.io-redis-streams-adapter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/socketio%2Fsocket.io-redis-streams-adapter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/socketio%2Fsocket.io-redis-streams-adapter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/socketio%2Fsocket.io-redis-streams-adapter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/socketio","download_url":"https://codeload.github.com/socketio/socket.io-redis-streams-adapter/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247305932,"owners_count":20917208,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["redis","socket-io","websocket"],"created_at":"2024-09-24T13:56:55.979Z","updated_at":"2025-04-05T08:04:01.540Z","avatar_url":"https://github.com/socketio.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Socket.IO Redis Streams adapter\n\nThe `@socket.io/redis-streams-adapter` package allows broadcasting packets between multiple Socket.IO servers.\n\n**Table of contents**\n\n- [Supported features](#supported-features)\n- [Installation](#installation)\n- [Usage](#usage)\n  - [With the `redis` package](#with-the-redis-package)\n  - [With the `redis` package and a Redis cluster](#with-the-redis-package-and-a-redis-cluster)\n  - [With the `ioredis` package](#with-the-ioredis-package)\n  - [With the `ioredis` package and a Redis cluster](#with-the-ioredis-package-and-a-redis-cluster)\n- [Options](#options)\n- [How it works](#how-it-works)\n- [License](#license)\n\n## Supported features\n\n| Feature                         | `socket.io` version | Support                                        |\n|---------------------------------|---------------------|------------------------------------------------|\n| Socket management               | `4.0.0`             | :white_check_mark: YES (since version `0.1.0`) |\n| Inter-server communication      | `4.1.0`             | :white_check_mark: YES (since version `0.1.0`) |\n| Broadcast with acknowledgements | `4.5.0`             | :white_check_mark: YES (since version `0.1.0`) |\n| Connection state recovery       | `4.6.0`             | :white_check_mark: YES (since version `0.1.0`) |\n\n## Installation\n\n```\nnpm install @socket.io/redis-streams-adapter redis\n```\n\n## Usage\n\n### With the `redis` package\n\n```js\nimport { createClient } from \"redis\";\nimport { Server } from \"socket.io\";\nimport { createAdapter } from \"@socket.io/redis-streams-adapter\";\n\nconst redisClient = createClient({ url: \"redis://localhost:6379\" });\n\nawait redisClient.connect();\n\nconst io = new Server({\n  adapter: createAdapter(redisClient)\n});\n\nio.listen(3000);\n```\n\n### With the `redis` package and a Redis cluster\n\n```js\nimport { createCluster } from \"redis\";\nimport { Server } from \"socket.io\";\nimport { createAdapter } from \"@socket.io/redis-streams-adapter\";\n\nconst redisClient = createCluster({\n  rootNodes: [\n    {\n      url: \"redis://localhost:7000\",\n    },\n    {\n      url: \"redis://localhost:7001\",\n    },\n    {\n      url: \"redis://localhost:7002\",\n    },\n  ],\n});\n\nawait redisClient.connect();\n\nconst io = new Server({\n  adapter: createAdapter(redisClient)\n});\n\nio.listen(3000);\n```\n\n### With the `ioredis` package\n\n```js\nimport { Redis } from \"ioredis\";\nimport { Server } from \"socket.io\";\nimport { createAdapter } from \"@socket.io/redis-streams-adapter\";\n\nconst redisClient = new Redis();\n\nconst io = new Server({\n  adapter: createAdapter(redisClient)\n});\n\nio.listen(3000);\n```\n\n### With the `ioredis` package and a Redis cluster\n\n```js\nimport { Cluster } from \"ioredis\";\nimport { Server } from \"socket.io\";\nimport { createAdapter } from \"@socket.io/redis-streams-adapter\";\n\nconst redisClient = new Cluster([\n  {\n    host: \"localhost\",\n    port: 7000,\n  },\n  {\n    host: \"localhost\",\n    port: 7001,\n  },\n  {\n    host: \"localhost\",\n    port: 7002,\n  },\n]);\n\nconst io = new Server({\n  adapter: createAdapter(redisClient)\n});\n\nio.listen(3000);\n```\n\n## Options\n\n| Name                | Description                                                                                                       | Default value  |\n|---------------------|-------------------------------------------------------------------------------------------------------------------|----------------|\n| `streamName`        | The name of the Redis stream.                                                                                     | `socket.io`    |\n| `maxLen`            | The maximum size of the stream. Almost exact trimming (~) is used.                                                | `10_000`       |\n| `readCount`         | The number of elements to fetch per XREAD call.                                                                   | `100`          |\n| `sessionKeyPrefix`  | The prefix of the key used to store the Socket.IO session, when the connection state recovery feature is enabled. | `sio:session:` |\n| `heartbeatInterval` | The number of ms between two heartbeats.                                                                          | `5_000`        |\n| `heartbeatTimeout`  | The number of ms without heartbeat before we consider a node down.                                                | `10_000`       |\n\n## How it works\n\nThe adapter will use a [Redis stream](https://redis.io/docs/data-types/streams/) to forward events between the Socket.IO servers.\n\nNotes:\n\n- a single stream is used for all namespaces\n- the `maxLen` option allows to limit the size of the stream\n- unlike the adapter based on Redis PUB/SUB mechanism, this adapter will properly handle any temporary disconnection to the Redis server and resume the stream\n- if [connection state recovery](https://socket.io/docs/v4/connection-state-recovery) is enabled, the sessions will be stored in Redis as a classic key/value pair\n\n## License\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsocketio%2Fsocket.io-redis-streams-adapter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsocketio%2Fsocket.io-redis-streams-adapter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsocketio%2Fsocket.io-redis-streams-adapter/lists"}