Registry / messaging / sc-redis

sc-redis

JSON →
library0.2.0jsnpmunverified

Redis adaptor for SocketCluster (version 0.2.0), allowing synchronization of pub/sub channels between SocketCluster and Redis. Messages published to Redis channels are automatically delivered to subscribed SocketCluster clients. This is an experimental, not production-ready solution; the recommended approach for horizontal scaling is SCC (SocketCluster Cluster). Release cadence is low; project is in maintenance mode.

npm install sc-redis
INSTALL
IMPORT
SIG · SC-REDIS
S
sc-redis
messagingjavascriptv0.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.

default
✓ var scRedis = require('sc-redis')
✗ import scRedis from 'sc-redis'
sc-redis is CJS-only; does not support ES modules. Use require().
attach
✓ scRedis.attach(broker)
✗ attach(broker)
attach is a method on the default export. Must be called on the required module.
detach
✓ scRedis.detach(broker)
✗ scRedis.detach()
detach requires the broker instance as argument to cleanly remove the adapter.

Shows how to attach sc-redis to a SocketCluster broker using require() and provide brokerOptions with Redis connection settings.

// In broker.js var scRedis = require('sc-redis'); module.exports.run = function (broker) { console.log(' >> Broker PID:', process.pid); scRedis.attach(broker); }; // In server.js (simplified) var SocketCluster = require('socketcluster'); var socketCluster = new SocketCluster({ workers: 1, brokers: 1, port: 8000, appName: 'myapp', brokerOptions: { host: process.env.REDIS_HOST || 'localhost', port: parseInt(process.env.REDIS_PORT || '6379'), password: process.env.REDIS_PASSWORD || undefined } });
Debug
Known issues
deprecatedsc-redis is experimental and not recommended for production use. SCC is the recommended approach for horizontal scaling.
fix
Migrate to SCC (SocketCluster Cluster) for production scaling.
affects: *
gotchaMessages published to Redis must be prefixed with 'o:' for JSON objects or 's:' for strings. Otherwise, they may not be parsed correctly.
fix
Prefix your Redis PUBLISH messages with 'o:' for JSON and 's:' for strings, e.g., PUBLISH channel 'o:{"key":"value"}'
affects: *
gotchasc-redis is CJS-only. Attempting to use ES import (import scRedis from 'sc-redis') will fail.
fix
Use require('sc-redis') instead of import.
affects: *
breakingsc-redis is not supported with SocketCluster versions that have changed the broker interface. Always check compatibility.
fix
Confirm that your version of SocketCluster is compatible with sc-redis 0.2.0. May require using an older SC version.
affects: socketcluster >= 4.x
Errors
Common errors & fixes
Error: Cannot find module 'sc-redis'
Module not installed in node_modules
fix
Run npm install sc-redis
TypeError: scRedis.attach is not a function
Using ES import instead of require()
fix
Change to var scRedis = require('sc-redis');
ReplyError: ERR wrong number of arguments for 'publish' command
Incorrect Redis PUBLISH call (missing channel or message)
fix
Ensure you use: PUBLISH channel message
Error: Redis connection to localhost:6379 failed - connect ECONNREFUSED
Redis server not running or wrong host/port
fix
Start Redis server or correct brokerOptions in server.js
Upgrade
Version history
0.2.0latest on npm
Audit
Dependencies
socketclusterrequiredPeer dependency; sc-redis attaches to a SocketCluster broker
redisrequiredUnderlying Redis client for connecting to Redis server
Agent activity
24 hits · last 30 days
node
22
OpenAI (training)
1
Resources
sc-redis — npm install sc-redis · libregistry