Registry / database / simple-redis-cache

simple-redis-cache

JSON →
library1.6.1jsnpmunverified

Simple Redis caching library for Node.js with connection pooling via generic-pool. Version 1.6.1 is the latest stable release as of 2025. It provides a straightforward key-value cache backed by Redis with configurable options for Redis connection, pool settings, serialization, logging, and expiration. Features both sync and async APIs, semaphore-based locking for distributed concurrency, and built-in statistics. It supports Node >=4 and uses ES6 features. Release cadence is low; the package appears to be in maintenance mode with infrequent updates.

npm install simple-redis-cache
INSTALL
IMPORT
SIG · SIMPLE-REDIS-CACHE
S
simple-redis-cache
databasejavascriptv1.6.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.

RedisCache
const RedisCache = require('simple-redis-cache')
import RedisCache from 'simple-redis-cache'
This package does not ship TypeScript types and does not support ESM imports. Use CommonJS require.
RedisCache (new instance)
const cache = new RedisCache({ redisOptions: { host: 'localhost', port: 6379 } })
const cache = new RedisCache({ host: 'localhost' })
Redis connection options must be nested under 'redisOptions' property, not flat on the options object.
set/get methods
cache.set('key', 'value'); cache.get('key').then(val => console.log(val))
cache.set('key', 'value', 'EX', 60)
Expiration is configured globally via options, not per-call. The set/get APIs are simple; no TTL argument.

Initializes a Redis cache with connection pooling, sets a value, retrieves it, and closes the connection.

const RedisCache = require('simple-redis-cache'); const cache = new RedisCache({ redisOptions: { host: process.env.REDIS_HOST || 'localhost', port: parseInt(process.env.REDIS_PORT || '6379'), password: process.env.REDIS_PASSWORD || '' }, poolOptions: { max: 10, min: 2 }, logger: console }); // Set and get values cache.set('greeting', 'Hello, world!'); cache.get('greeting').then(value => { console.log('Cached value:', value); }); // Clean up cache.end();
Debug
Known issues
gotchaExpiration must be configured globally; per-call TTL is NOT supported.
fix
Set defaultExpiration and defaultExpirationMode in options (not documented but present in source). Review source or use an alternative library if per-key TTL is required.
affects: >=1.0.0
gotchaThe package does not use a Promise-based API internally for all methods; some are callback-based or sync.
fix
Ensure you are using the documented async methods (get, set return promises). For sync methods, handle callbacks. Check source if unsure.
affects: >=1.0.0
deprecatedThe package depends on node_redis (v2.x) which is deprecated in favor of redis v4.
fix
Consider migrating to a modern caching library like ioredis or redis v4 directly.
affects: >=1.0.0
gotchaWhen using poolOptions, the underlying generic-pool may have breaking changes between versions.
fix
Pin your generic-pool version to match the one used by simple-redis-cache, or test thoroughly after updates.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: cache.set is not a function
Importing the package as default ES module instead of CommonJS.
fix
Use const RedisCache = require('simple-redis-cache') instead of import.
Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED
Redis server not running or wrong host/port.
fix
Ensure Redis is running and options.redisOptions.host/port are correct.
TypeError: Cannot read property 'get' of undefined
Forgetting to instantiate RedisCache (using RedisCache.set directly instead of new RedisCache().set).
fix
Create an instance: const cache = new RedisCache(); then call cache.set()
Upgrade
Version history
1.6.1latest on npm
Audit
Dependencies
redisrequiredRequired to connect to Redis server; the package wraps node_redis.
generic-poolrequiredUsed for connection pooling to manage Redis connections efficiently.
Agent activity
8 hits · last 30 days
node
6
Meta
1
Resources
simple-redis-cache — npm install simple-redis-cache · libregistry