Registry / database / cache-manager-ioredis

cache-manager-ioredis

JSON →
library2.1.0jsnpmunverified

cache-manager-ioredis provides a Redis store for the `node-cache-manager` library, leveraging the `ioredis` client for connecting to Redis. The package, currently at version 2.1.0, integrates `ioredis` by transparently passing configuration options to the underlying client, aiming for a simple wrapper. It differentiates itself from `node-cache-manager-redis-store` by opting for `ioredis` over `node_redis`, which offers better performance and features like Redis Cluster support. While this specific package's last update mentioned in the prompt is v2.1.0, the broader `cache-manager` ecosystem has evolved, with the main `cache-manager` library (v6+) now recommending `Keyv` as its primary storage adapter and explicitly moving away from direct support for `cache-manager-ioredis` and its 'yet' variants. This means `cache-manager-ioredis` is primarily suitable for older `node-cache-manager` versions or projects where `ioredis` integration is specifically required without migrating to `Keyv` adapters. Its release cadence is infrequent, reflecting its mature but superseded status within the evolving `cache-manager` landscape.

npm install cache-manager-ioredis
INSTALL
IMPORT
SIG · CACHE-MANAGER-IORE
C
cache-manager-ioredis
databasejavascriptv2.1.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

redisStore
import redisStore from 'cache-manager-ioredis';
const redisStore = require('cache-manager-ioredis');
While CommonJS `require` is shown in examples, ES Modules `import` is preferred in modern Node.js environments. Type definitions for `cache-manager-ioredis` are available via `@types/cache-manager-ioredis`.
caching
import { caching } from 'cache-manager';
const cacheManager = require('cache-manager'); const { caching } = cacheManager;
The `caching` function is a named export from `cache-manager` in newer versions, though older examples might show it differently.
redisClient
const redisClient = redisCache.store.getClient();
This method returns the underlying `ioredis` client instance, allowing direct interaction. Be aware of breaking changes related to its return type/API in older updates.

This quickstart demonstrates how to initialize `cache-manager` with `cache-manager-ioredis` as the store, perform basic set, get, and delete operations, and use the `wrap` function for memoization. It also includes essential error handling for Redis connection issues.

import { caching } from 'cache-manager'; import redisStore from 'cache-manager-ioredis'; const redisCache = caching({ store: redisStore, host: 'localhost', port: 6379, password: process.env.REDIS_PASSWORD ?? 'XXXXX', // Use environment variable for security db: 0, ttl: 600 }); const redisClient = redisCache.store.getClient(); redisClient.on('error', (error) => { console.error('Redis connection error:', error); // Implement robust error handling, e.g., logging, alerts, or graceful degradation }); const ttl = 5; redisCache.set('foo', 'bar', { ttl: ttl }, (err) => { if (err) { console.error('Failed to set cache:', err); return; } console.log('Key "foo" set.'); redisCache.get('foo', (err, result) => { if (err) { console.error('Failed to get cache:', err); return; } console.log('Retrieved "foo":', result); redisCache.del('foo', (err) => { if (err) console.error('Failed to delete cache:', err); else console.log('Key "foo" deleted.'); }); }); }); function getUser(id, cb) { setTimeout(() => { console.log("Returning user from slow database."); cb(null, { id: id, name: 'Bob' }); }, 100); } const userId = 123; const key = `user_${userId}`; redisCache.wrap(key, (cb) => { getUser(userId, cb); }, { ttl: ttl }, (err, user) => { if (err) console.error('Wrap operation failed:', err); else console.log('Wrapped user:', user); });
Debug
Known issues
breakingThe update of `ioredis` from v2.5.0 to v3.0.0 in `cache-manager-ioredis` v1.0.1 introduced potential breaking changes. If you were directly interacting with the underlying `ioredis` client via `cache.store.getClient()`, its API or behavior might have changed.
fix
Review `ioredis` v3.0.0 release notes and adjust any direct `ioredis` client interactions. Prioritize using the `cache-manager` API methods instead of direct client calls where possible.
affects: >=1.0.1
gotchaThe `cache-manager` ecosystem (v6+) has shifted its primary storage adapter recommendation to `Keyv` and no longer directly supports `cache-manager-ioredis` (or its 'yet' fork) for new development. While `cache-manager-ioredis` might still work with older `cache-manager` versions, it's not the recommended approach for modern `cache-manager` projects.
fix
For new projects or upgrades to `cache-manager` v6+, consider migrating to `@keyv/redis` or using `KeyvAdapter` to wrap `cache-manager-ioredis` if necessary. Consult the latest `cache-manager` documentation for recommended practices.
affects: >=2.1.0
gotchaRedis connection errors (e.g., `ECONNREFUSED`, `ENOTFOUND`) are common and can lead to application crashes if not handled gracefully. The `ioredis` client emits an 'error' event that must be listened to.
fix
Always attach an error listener to the `ioredis` client instance obtained via `redisCache.store.getClient().on('error', handler)`. Implement robust error handling, such as logging the error, falling back to a database, or implementing retry logic. Avoid letting unhandled `ioredis` errors crash your Node.js process.
affects: >=1.0.0
Errors
Common errors & fixes
Error: getaddrinfo ENOTFOUND localhost:6379
The application could not resolve the hostname or connect to the Redis server at the specified host and port.
fix
Ensure the Redis server is running and accessible from your application's environment. Verify the `host` and `port` configuration options for `cache-manager-ioredis`. If using a non-default hostname, check your `/etc/hosts` file or DNS settings.
TypeError: store.set is not a function
The `store` option passed to `cacheManager.caching` is not a valid cache store instance (e.g., `redisStore` was not imported correctly or initialized improperly).
fix
Verify that `cache-manager-ioredis` is correctly installed (`npm install cache-manager-ioredis`) and that `redisStore` is imported and passed as the `store` option: `caching({ store: redisStore, ... })`.
Redis connection to 127.0.0.1:6379 failed - NOAUTH Authentication required.
The Redis server requires a password, but none was provided in the `cache-manager-ioredis` configuration.
fix
Include the `password` option in your `cache-manager-ioredis` configuration with the correct Redis password: `caching({ store: redisStore, password: 'your_redis_password', ... })`. Consider using environment variables for sensitive credentials.
Upgrade
Version history
2.1.0latest on npm
Audit
Dependencies
cache-managerrequiredCore caching abstraction layer.
ioredisrequiredUnderlying Redis client library.
Agent activity
14 hits · last 30 days
node
12
OpenAI (training)
1
Resources
cache-manager-ioredis — npm install cache-manager-ioredis · libregistry