Registry / database / redis-cache-client

redis-cache-client

JSON →
library1.0.1jsnpmunverified

A lightweight abstraction layer for node-redis that simplifies caching with automatic key prefixing, TTL support, and cache purging. Current stable version is 1.0.1. This package wraps the popular redis client to provide a clean API for set, get, and purge operations without exposing raw redis commands. It uses a minimalistic design with no external dependencies beyond node-redis, ideal for applications needing a simple caching helper rather than a full-featured cache library.

npm install redis-cache-client
INSTALL
IMPORT
SIG · REDIS-CACHE-CLIENT
R
redis-cache-client
databasejavascriptv1.0.1
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.

CacheClient
var CacheClient = require('redis-cache-client');
import CacheClient from 'redis-cache-client';
The package is CommonJS only; ESM import may not work without a bundler.
redis
var redis = require('redis'); var cache = CacheClient({ client: redis.createClient() });
var cache = CacheClient();
The redis client must be created separately and passed in the options object.
get
cache.get('key', callback);
var value = cache.get('key');
get is asynchronous; it does not return a value but invokes a callback.
purge
cache.purge(callback);
cache.purge() without callback;
purge is asynchronous; the callback is recommended to handle errors.

Creates a redis client, initializes cache client with prefix, sets a value with TTL, retrieves it, then purges all prefixed keys.

var redis = require('redis'); var CacheClient = require('redis-cache-client'); var client = redis.createClient({ url: process.env.REDIS_URL || 'redis://localhost:6379' }); var cache = CacheClient({ client: client, prefix: 'myapp:' }); cache.set('user:1', { name: 'Alice' }, 360, function(err) { if (err) console.error('Set error:', err); else { cache.get('user:1', function(err, result) { if (err) console.error('Get error:', err); else console.log('Cached user:', result); cache.purge(function(err) { if (err) console.error('Purge error:', err); else console.log('All prefixed keys cleared'); client.quit(); }); }); } });
Debug
Known issues
gotchaThe prefix must end with a delimiter (e.g., ':') to avoid key collisions; the library does not add one automatically.
fix
Use a prefix like 'myprefix:' with a trailing colon.
affects: >=0.0.0
gotchaTTL is specified in seconds, not milliseconds.
fix
Provide TTL as number of seconds (e.g., 360 for 6 minutes).
affects: >=0.0.0
gotchaThe library does not support promises; only callbacks are used.
fix
Wrap calls with a promise library if needed.
affects: >=0.0.0
gotchaget returns the parsed object; if stored data is not valid JSON, it may throw.
fix
Ensure only JSON-serializable data is stored with set.
affects: >=0.0.0
Errors
Common errors & fixes
Redis connection error: Redis connection to 127.0.0.1:6379 failed
Redis server is not running or not accessible.
fix
Start redis server with 'redis-server' or set REDIS_URL to a valid endpoint.
TypeError: redis.createClient is not a function
The redis package is not installed or incorrectly imported.
fix
Install redis: npm install redis
TypeError: Cannot read property 'set' of undefined
CacheClient was called without creating a client or invalid options.
fix
Call CacheClient with an object containing a valid 'client' key.
Error: The 'callback' argument must be of type function. Received undefined
A required callback is missing in set, get, or purge.
fix
Provide a callback function as the last argument.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies
redisrequiredRequired to connect to Redis and perform operations
Agent activity
10 hits · last 30 days
node
8
Meta
1
Resources
redis-cache-client — npm install redis-cache-client · libregistry