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.fixMigrate 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.fixPrefix 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.fixUse require('sc-redis') instead of import. affects: *
breakingsc-redis is not supported with SocketCluster versions that have changed the broker interface. Always check compatibility.fixConfirm 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
fixRun npm install sc-redis
TypeError: scRedis.attach is not a function
Using ES import instead of require()
fixChange to var scRedis = require('sc-redis'); ReplyError: ERR wrong number of arguments for 'publish' command
Incorrect Redis PUBLISH call (missing channel or message)
fixEnsure you use: PUBLISH channel message
Error: Redis connection to localhost:6379 failed - connect ECONNREFUSED
Redis server not running or wrong host/port
fixStart Redis server or correct brokerOptions in server.js
Audit
Dependencies
socketclusterrequiredPeer dependency; sc-redis attaches to a SocketCluster broker
redisrequiredUnderlying Redis client for connecting to Redis server