Registry / devops / redis-ws-discovery

redis-ws-discovery

JSON →
library0.2.0jsnpmunverified

Redis WS Discovery (v0.2.0) enables WebSocket servers and clients to discover each other via Redis pub/sub without a central registry. Each server announces its identity (e.g., host, port) to a Redis channel, and clients (or other servers) listen for announcements to build a live list of available peers. Built on ioredis (^5.4.1), shipped with TypeScript definitions, requires Node >=20. Lightweight alternative to etcd or Consul for WebSocket topologies in Redis-heavy stacks. Released under new BSD license.

npm install redis-ws-discovery
INSTALL
IMPORT
SIG · REDIS-WS-DISCOVERY
R
redis-ws-discovery
devopsjavascriptv0.2.0
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.

WsDiscoveryServer
✓ import { WsDiscoveryServer } from 'redis-ws-discovery'
✗ const { WsDiscoveryServer } = require('redis-ws-discovery')
TypeScript-defined class for server-side discovery registration
WsDiscoveryClient
✓ import { WsDiscoveryClient } from 'redis-ws-discovery'
✗ const WsDiscoveryClient = require('redis-ws-discovery').WsDiscoveryClient
Client for listening to server announcements
createDiscovery
✓ import { createDiscovery } from 'redis-ws-discovery'
Factory function returning both server and client instances

Shows basic server discovery registration and client discovery listening via Redis pub/sub.

import Redis from 'ioredis'; import { WsDiscoveryServer, WsDiscoveryClient } from 'redis-ws-discovery'; const redis = new Redis({ host: 'localhost', port: 6379 }); // Server announces itself as 'ws://localhost:3000' const server = new WsDiscoveryServer(redis, { channel: 'ws:discovery', identity: { url: 'ws://localhost:3000' }, ttl: 30000 }); server.start(); // Client listens for announcements const client = new WsDiscoveryClient(redis, { channel: 'ws:discovery' }); client.on('peer', (peer) => { console.log('Discovered peer:', peer.url); }); client.start(); // Stop after 10 seconds setTimeout(() => { server.stop(); client.stop(); redis.quit(); }, 10000);
Debug
Known issues
gotchaBoth server and client require a shared Redis instance and same channel name to discover each other.
fix
Ensure all instances use the same Redis connection and channel string.
affects: >=0.0.0
breakingRequires Node >=20.0.0, incompatible with older Node.js versions.
fix
Upgrade Node.js to v20+ or use an earlier version of the package if available.
affects: >=0.2.0
deprecatedioredis peer dependency is required; using other Redis clients (e.g., node-redis) will cause runtime errors.
fix
Install ioredis@^5.4.1 as a dependency.
affects: >=0.0.0
gotchaIdentity object must contain a 'url' field; any custom fields may be optional but the package expects at least this.
fix
Include a 'url' property in the identity object passed to WsDiscoveryServer.
affects: >=0.0.0
gotchaTTL (time-to-live) for server announcements must be set explicitly; default is 30000ms.
fix
Configure ttl in options to control re-announcement frequency.
affects: >=0.0.0
gotchaClient emits 'peer' event only when a new server appears or updates; it does not emit the initial list on connect.
fix
Manually fetch active servers after client start using a separate mechanism if needed.
affects: >=0.0.0
gotchaStopping server does not clear its announcement from Redis peers immediately; they will be removed after TTL expires.
fix
Optionally implement a manual removal via Redis client before stopping the server.
affects: >=0.0.0
Errors
Common errors & fixes
Error: Cannot find module 'ioredis'
Missing peer dependency ioredis
fix
npm install ioredis@^5.4.1
TypeError: redis.subscribe is not a function
Passed a Redis client that does not support pub/sub (e.g., node-redis instead of ioredis)
fix
Install ioredis and use it as the Redis client
Error [ERR_REQUIRE_ESM]: require() of ES Module not supported
Using CommonJS require() on an ESM-only package (since v0.2.0 may be ESM)
fix
Use import syntax or enable ESM in your project
TypeError: Invalid channel: must be a non-empty string
Channel name was not provided or was empty
fix
Set a valid channel string in options
Error: identity.url is required
Identity object missing 'url' field
fix
Add 'url' property to the identity object passed to WsDiscoveryServer
Upgrade
Version history
0.2.0latest on npm
Audit
Dependencies
ioredisrequiredPeer dependency: Redis client library for pub/sub and data operations
Agent activity
4 hits · last 30 days
node
4
Resources
redis-ws-discovery — npm install redis-ws-discovery · libregistry