Registry / storage / cache-service-redis

cache-service-redis

JSON →
library2.0.2jsnpmunverified

A Redis plugin for cache-service and a standalone Redis wrapper for Node.js (v2.0.2). Provides features like background refresh, automatic serialization/deserialization of objects, flexible Redis connection configuration (via env var, URL, or explicit params), and built-in logging with verbose flag. Compared to vanilla node_redis, it offers a more logical API (e.g., mset() accepts an object and supports per-key expiration). Compatible with cache-service and superagent-cache, and includes redis mock support for testing. The library is stable but in maintenance mode; no recent updates.

npm install cache-service-redis
INSTALL
IMPORT
SIG · CACHE-SERVICE-REDI
C
cache-service-redis
storagejavascriptv2.0.2
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
const CacheServiceRedis = require('cache-service-redis');
import CacheServiceRedis from 'cache-service-redis';
This package is CJS-only. ESM import will fail.
constructor
const redisCache = new CacheServiceRedis({ redisEnv: 'REDISCLOUD_URL' });
const redisCache = new CacheServiceRedis.RedisCache({ redisEnv: 'REDISCLOUD_URL' });
The module exports the class directly.
instance methods
redisCache.set('key', 'value', 3600);
redisCache.set('key', 'value', { expiration: 3600 });
Expiration (optional) is passed as a number (seconds), not an object.

Instantiates cache-service-redis with a Redis URL, sets a serialized object with 60s TTL, then retrieves it.

const CacheServiceRedis = require('cache-service-redis'); const redisCache = new CacheServiceRedis({ redisUrl: process.env.REDIS_URL ?? 'redis://localhost:6379', defaultExpiration: 3600, verbose: false }); redisCache.set('mykey', { data: 'hello' }, 60) .then(() => redisCache.get('mykey')) .then(result => console.log(result)) // { data: 'hello' } .catch(err => console.error(err));
Debug
Known issues
breakingv2.x changed the constructor signature; `redisData` is now an object with `port`, `hostname`, `auth` instead of a flat string.
fix
Use { redisData: { port: 6379, hostname: 'localhost', auth: 'pass' } } instead of a single string.
affects: >=2.0.0
deprecatedThe `redisEnv` option reads from `process.env[redisEnv]`; this is fragile and not recommended for production. Prefer `redisUrl` or `redisData`.
fix
Use `redisUrl` with a full connection string or `redisData` object.
affects: >=1.0.0
gotchaIf `backgroundRefreshInterval` >= `backgroundRefreshMinTtl`, an exception is thrown unless `backgroundRefreshIntervalCheck` is false.
fix
Set `backgroundRefreshInterval` < `backgroundRefreshMinTtl` (defaults: 60000 < 70000).
affects: >=1.0.0
gotchaWhen used with `cache-service`, the `verbose` property is overridden by `cache-service`'s verbose flag.
fix
Set verbose on cache-service instance instead.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: CacheServiceRedis is not a constructor
Using ES import (`import CacheServiceRedis from 'cache-service-redis'`) on a CJS module.
fix
Use `const CacheServiceRedis = require('cache-service-redis');`
Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED
Redis server not running or connection config is wrong.
fix
Ensure Redis is running and check connection parameters (host, port, auth).
TypeError: redisCache.set is not a function
Instance created with incorrect options or not using the class directly.
fix
Verify import: `const CacheServiceRedis = require('cache-service-redis');` and instantiate with `new CacheServiceRedis(...)`.
Upgrade
Version history
2.0.2latest on npm
Audit
Dependencies
redisrequiredUnderlying Redis client used for all operations
cache-serviceoptionalOptional integration with cache-service for multi-tier caching
Agent activity
32 hits · last 30 days
node
30
OpenAI (training)
1
Resources