Registry / database / redis-lru-cache

redis-lru-cache

JSON →
library1.0.16jsnpmunverified

A composite cache that combines an in-memory LRU layer with a Redis backend, using Redis pub/sub to stay synchronized across multiple processes or cluster nodes. Version 1.0.16 is the latest stable release, with no recent updates since its initial publish. It provides configurable LRU size, Redis TTL, and optional automatic clearing on instantiation. Differentiators include built-in cluster awareness without external coordination and an optional retrieveItem callback for lazy-loading missing keys. Requires Redis server 2.8.3+ and the `redis` npm package v2.x.

npm install redis-lru-cache
INSTALL
IMPORT
SIG · REDIS-LRU-CACHE
R
redis-lru-cache
databasejavascriptv1.0.16
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.

RedisCache
const RedisCache = require('redis-lru-cache');
import RedisCache from 'redis-lru-cache';
This package is CommonJS-only and does not export ESM. Use require().
RedisCache
const RedisCache = require('redis-lru-cache').RedisCache;
const RedisCache = require('redis-lru-cache').default;
The package exports the constructor directly, not as a named export. Only use .RedisCache if you have transpilation issues.
instance.set
cache.set(key, value, callback);
cache.set(key, value);
set() requires a callback. Omitting it will crash in Node.js with a 'callback is not a function' error.

Demonstrates basic usage of redis-lru-cache: instantiation, set, get, and remove operations with required callbacks.

const RedisCache = require('redis-lru-cache'); const cache = new RedisCache({ cacheId: 'my-cache', lru: { max: 5000 }, clear: false }); const key = '/test/key'; const value = { message: 'hello' }; // Set value with callback cache.set(key, value, (err) => { if (err) console.error('Set error:', err); else console.log('Value set successfully'); }); // Get value with callback cache.get(key, (err, data) => { if (err) console.error('Get error:', err); else console.log('Retrieved:', data); }); // Remove value cache.remove(key, (err) => { if (err) console.error('Remove error:', err); else console.log('Value removed'); });
Debug
Known issues
breakingThe 'redis' package peer dependency is locked to version 2.x. Using redis v3 or v4 will cause compatibility issues (e.g., client creation differences).
fix
Install redis@2.x: npm install redis@^2.8
affects: >=1.0.0
deprecatedCallback-based API is used throughout. Promises/async-await are not supported natively.
fix
Wrap calls with util.promisify or use a promise wrapper.
affects: >=1.0.0
breakingIf `clear: true` is passed, the cache will call `FLUSHALL` on instantiation, wiping all keys in the Redis database. This can cause data loss in production.
fix
Set `clear: false` on instantiation to avoid accidental flushing.
affects: >=1.0.0
gotchaThe `cacheId` must be unique across processes sharing the same Redis instance. Duplicate IDs can cause cross-talk and incorrect cache updates via pub/sub.
fix
Use a unique identifier per process (e.g., process.pid + random string).
affects: >=1.0.0
gotchaset() expects a callback as third argument. Omitting it throws 'callback is not a function'. This is easy to miss when switching from promise-based libraries.
fix
Always provide a callback function even if you do nothing with it.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED
Redis server is not running or not accessible.
fix
Start Redis server: redis-server, or verify connection settings.
callback is not a function
Calling cache.set() or cache.get() without a callback parameter, or passing a non-function.
fix
Provide a callback: cache.set(key, value, (err, result) => { ... })
typeerror: Cannot read property 'set' of undefined
Instantiated cache before the Redis client is ready, or the constructor failed silently (e.g., missing redis package).
fix
Ensure redis@2.x is installed and the dependency is properly required. The instance is created synchronously but the internal client may not be ready; use the callback in set/get to catch errors.
Upgrade
Version history
1.0.16latest on npm
Audit
Dependencies
redisrequiredRequired for Redis cache backend and pub/sub synchronization. Must be v2.x.
Agent activity
20 hits · last 30 days
node
16
Meta
1
Resources
redis-lru-cache — npm install redis-lru-cache · libregistry