{"_id":"@aegis-fluxion/redis-adapter","name":"@aegis-fluxion/redis-adapter","dist-tags":{"latest":"0.1.0"},"versions":{"0.1.0":{"name":"@aegis-fluxion/redis-adapter","version":"0.1.0","description":"Redis Pub/Sub adapter for horizontally scaled SecureServer instances.","type":"module","main":"./dist/index.cjs","module":"./dist/index.js","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs","default":"./dist/index.js"}},"publishConfig":{"access":"public"},"sideEffects":false,"scripts":{"build":"tsup","dev":"tsup --watch","typecheck":"tsc --noEmit","test":"vitest run --passWithNoTests","test:watch":"vitest --passWithNoTests","clean":"node -e \"import('node:fs').then(({ rmSync }) => rmSync('dist', { recursive: true, force: true }))\"","prepublishOnly":"npm run clean && npm run build && npm run typecheck && npm run test"},"dependencies":{"@aegis-fluxion/core":"^0.7.2","redis":"^5.8.2"},"devDependencies":{"tsup":"^8.3.5","typescript":"^5.8.3","vitest":"^3.2.4"},"engines":{"node":">=18.18.0"},"keywords":["redis","pubsub","horizontal-scaling","websocket","secure-messaging"],"license":"MIT","gitHead":"c13f44be6ff0449a22ab996bc9c15df306b7552a","_id":"@aegis-fluxion/redis-adapter@0.1.0","_nodeVersion":"24.13.0","_npmVersion":"11.6.2","dist":{"integrity":"sha512-1IqPir0s3yYBMZobykNH7lCUV9kwyM8Spmizj5y8a15/ydUXEjjIQY129HhBRsGcV/tcyt+IJhBifBL7PloABg==","shasum":"87442aa4965e08de666951f377b6eaeac47abcf5","tarball":"https://registry.npmjs.org/@aegis-fluxion/redis-adapter/-/redis-adapter-0.1.0.tgz","fileCount":8,"unpackedSize":31308,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIDN2Nyh3H6S6WU+zHfYH0EH/QG3LxUJmX03e54iYm9eXAiBP2Dds4M4eDfRghoUtNAWqX77wnagh0yISSS/YEhgLYQ=="}]},"_npmUser":{"name":"donboz","email":"muratbatak052005@gmail.com"},"directories":{},"maintainers":[{"name":"donboz","email":"muratbatak052005@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/redis-adapter_0.1.0_1776282962433_0.386262241501502"},"_hasShrinkwrap":false}},"time":{"created":"2026-04-15T19:56:02.268Z","0.1.0":"2026-04-15T19:56:02.558Z","modified":"2026-04-15T19:56:02.953Z"},"maintainers":[{"name":"donboz","email":"muratbatak052005@gmail.com"}],"description":"Redis Pub/Sub adapter for horizontally scaled SecureServer instances.","keywords":["redis","pubsub","horizontal-scaling","websocket","secure-messaging"],"license":"MIT","readme":"# @aegis-fluxion/redis-adapter\r\n\r\nRedis Pub/Sub adapter for horizontal scaling of `SecureServer` instances.\r\n\r\nVersion: **0.1.0**\r\n\r\n---\r\n\r\n## What it does\r\n\r\n`RedisSecureServerAdapter` synchronizes encrypted event fanout across multiple Node.js processes/instances:\r\n\r\n- **Broadcast replication** (`server.emit(...)`)\r\n- **Room replication** (`server.to(room).emit(...)`)\r\n\r\nThis enables horizontal scaling while keeping your existing `@aegis-fluxion/core` application event model.\r\n\r\n---\r\n\r\n## Install\r\n\r\n```bash\r\nnpm install @aegis-fluxion/redis-adapter @aegis-fluxion/core redis ws\r\n```\r\n\r\n---\r\n\r\n## Quick Start\r\n\r\n```ts\r\nimport { SecureServer } from \"@aegis-fluxion/core\";\r\nimport { RedisSecureServerAdapter } from \"@aegis-fluxion/redis-adapter\";\r\n\r\nconst adapter = new RedisSecureServerAdapter({\r\n  redisUrl: \"redis://127.0.0.1:6379\",\r\n  channel: \"aegis-fluxion:cluster:v1\"\r\n});\r\n\r\nconst server = new SecureServer({\r\n  host: \"127.0.0.1\",\r\n  port: 8080,\r\n  adapter\r\n});\r\n\r\nserver.on(\"connection\", (client) => {\r\n  client.join(\"ops\");\r\n});\r\n\r\nserver.on(\"ops:ping\", (payload) => {\r\n  console.log(\"Received:\", payload);\r\n});\r\n\r\n// Replicated to all instances + local clients.\r\nserver.emit(\"cluster:announcement\", { from: \"instance-a\" });\r\n\r\n// Replicated to room members across all instances.\r\nserver.to(\"ops\").emit(\"ops:ping\", { from: \"instance-a\" });\r\n```\r\n\r\n---\r\n\r\n## Two-instance topology example\r\n\r\n```ts\r\nimport { SecureServer } from \"@aegis-fluxion/core\";\r\nimport { RedisSecureServerAdapter } from \"@aegis-fluxion/redis-adapter\";\r\n\r\nconst sharedRedisUrl = \"redis://127.0.0.1:6379\";\r\nconst sharedChannel = \"aegis-fluxion:cluster:prod\";\r\n\r\nconst adapterA = new RedisSecureServerAdapter({\r\n  redisUrl: sharedRedisUrl,\r\n  channel: sharedChannel\r\n});\r\n\r\nconst adapterB = new RedisSecureServerAdapter({\r\n  redisUrl: sharedRedisUrl,\r\n  channel: sharedChannel\r\n});\r\n\r\nconst serverA = new SecureServer({ host: \"127.0.0.1\", port: 8081, adapter: adapterA });\r\nconst serverB = new SecureServer({ host: \"127.0.0.1\", port: 8082, adapter: adapterB });\r\n\r\nserverA.on(\"connection\", (client) => client.join(\"alerts\"));\r\nserverB.on(\"connection\", (client) => client.join(\"alerts\"));\r\n\r\nserverA.to(\"alerts\").emit(\"alerts:new\", {\r\n  level: \"info\",\r\n  source: \"server-a\"\r\n});\r\n```\r\n\r\n---\r\n\r\n## API\r\n\r\n### `RedisSecureServerAdapter(options?)`\r\n\r\n```ts\r\nnew RedisSecureServerAdapter({\r\n  redisUrl?: string;\r\n  channel?: string;\r\n  publisher?: RedisClientType;\r\n  subscriber?: RedisClientType;\r\n  onError?: (error: Error) => void;\r\n});\r\n```\r\n\r\n- `redisUrl`: Redis connection URL (default Redis client behavior if omitted)\r\n- `channel`: Pub/Sub channel name (default internal cluster channel)\r\n- `publisher` / `subscriber`: Optional prebuilt Redis clients for custom lifecycle control\r\n- `onError`: Optional adapter-level error hook\r\n\r\n### Lifecycle methods\r\n\r\n- `attach(server)` — binds adapter to one `SecureServer`\r\n- `publish(message)` — publishes normalized replication payload\r\n- `detach(server)` — unsubscribes and closes owned clients\r\n\r\n---\r\n\r\n## Operational notes\r\n\r\n- Attach one adapter instance to one `SecureServer`.\r\n- Use a shared Redis channel across all instances participating in one cluster.\r\n- Keep Redis ACL/auth and network policies strict in production.\r\n- `originServerId` filtering prevents same-node replay loops.\r\n\r\n---\r\n\r\n## Development\r\n\r\nFrom repository root:\r\n\r\n```bash\r\nnpm run typecheck -w @aegis-fluxion/redis-adapter\r\nnpm run test -w @aegis-fluxion/redis-adapter\r\nnpm run build -w @aegis-fluxion/redis-adapter\r\n```\r\n\r\n---\r\n\r\n## License\r\n\r\nMIT\r\n","readmeFilename":"README.md","_rev":"1-a256e614fa984ce1ab10e3d1125a1bcb"}