Registry / database / sharedb-redis-pubsub

sharedb-redis-pubsub

JSON →
library5.1.0jsnpmunverified

Redis pub/sub adapter for ShareDB, enabling horizontal scalability by forwarding operations across multiple server nodes in a cluster. Stable version 5.1.0, maintained as part of the ShareDB ecosystem. Uses Redis publish/subscribe to broadcast operations to all nodes, ensuring no race conditions with persistence. Compared to other pub/sub adapters (e.g., Kafka), it is lightweight and leverages Redis's built-in pub/sub, making it ideal for setups already using Redis. Requires a Redis client instance and ShareDB backend.

npm install sharedb-redis-pubsub
INSTALL
IMPORT
SIG · SHAREDB-REDIS-PUBS
S
sharedb-redis-pubsub
databasejavascriptv5.1.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.

ShareDBRedisPubSub
const ShareDBRedisPubSub = require('sharedb-redis-pubsub'); const pubsub = ShareDBRedisPubSub({client: redisClient});
import ShareDBRedisPubSub from 'sharedb-redis-pubsub'; // ESM import may not work correctly; package is CommonJS
Package exports a factory function that expects an options object with a 'client' property. use require() for CommonJS; ESM import may not work out of the box.
default export
const createPubSub = require('sharedb-redis-pubsub'); const pubsub = createPubSub({client: redisClient});
const PubSub = require('sharedb-redis-pubsub').PubSub; // No named export 'PubSub'
The package exports a single factory function as the default export. There is no class or named export.
types
// No TypeScript types are shipped; use @types/sharedb-redis-pubsub if available or declare module
import { PubSubOptions } from 'sharedb-redis-pubsub'; // Types not provided
This package does not include TypeScript declarations. Consider using a declaration file or wrapping with 'any'.

Creates a Redis pub/sub adapter for ShareDB, connects to Redis, and submits an operation.

const ShareDB = require('sharedb'); const redis = require('redis'); const redisPubsub = require('sharedb-redis-pubsub'); // Create Redis client (replace with your Redis connection details) const redisClient = redis.createClient({url: 'redis://localhost:6379'}); await redisClient.connect(); // Create pub/sub adapter const pubsub = redisPubsub({client: redisClient}); // Create ShareDB backend with Redis pub/sub const backend = new ShareDB({db: null, pubsub: pubsub}); // Replace db with actual database adapter // Example: agent connection const connection = backend.connect(); const doc = connection.get('examples', '1'); doc.fetch(function(err) { if (err) throw err; doc.submitOp([{p: ['name'], od: '', oi: 'Hello World'}], function(err) { if (err) throw err; console.log('Operation submitted'); }); });
Debug
Known issues
breakingVersion 4.x dropped support for old Redis client library (ioredis vs node_redis). Check client compatibility.
fix
Upgrade to v5 or ensure Redis client meets new requirements. Use 'redis' v4+ or 'ioredis'.
affects: <5.0.0
deprecatedThe option 'prefix' is deprecated in favor of 'channelPrefix'.
fix
Use 'channelPrefix' instead of 'prefix' when constructing the adapter.
affects: >=4.0.0 <5.0.0
gotchaRedis client must be connected before passing to the adapter. Unconnected client leads to silent failures.
fix
Call client.connect() (for redis v4+) or ensure client is ready before creating pubsub adapter.
affects: *
breakingShareDB >=2.0 requires a different pubsub adapter interface. This adapter may be incompatible.
fix
Check ShareDB version compatibility. Use sharedb-redis-pubsub v5 with ShareDB v1.x.
affects: >=5.0.0
gotchaIf using ioredis, ensure compatibility. Some options (e.g., 'retryStrategy') may cause issues.
fix
Test with your specific Redis client library. Refer to issues on GitHub for ioredis workarounds.
affects: *
Errors
Common errors & fixes
Error: Redis connection in pubsub adapter is required
The adapter was instantiated without a valid Redis client or the client was not connected.
fix
Pass a connected Redis client object: {client: myConnectedRedisClient}
TypeError: redisPubsub is not a function
Incorrect import style: trying to use the module as a class or named export.
fix
Use: const redisPubsub = require('sharedb-redis-pubsub'); then call as redisPubsub({client: ...}).
Error: Cannot find module 'sharedb-redis-pubsub'
Package not installed or missing from node_modules.
fix
Run: npm install sharedb-redis-pubsub
Upgrade
Version history
5.1.0latest on npm
Audit
Dependencies
sharedbrequiredPeer dependency: this adapter is designed to be used with ShareDB backend for pub/sub functionality
redisrequiredPeer dependency: requires an existing Redis client instance (e.g., from 'redis' or 'ioredis') to connect to Redis
Agent activity
14 hits · last 30 days
node
10
Meta
2
Resources
sharedb-redis-pubsub — npm install sharedb-redis-pubsub · libregistry