{"id":12942,"library":"cache-manager-ioredis","title":"cache-manager-ioredis","description":"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.","status":"maintenance","version":"2.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/dabroek/node-cache-manager-ioredis","tags":["javascript"],"install":[{"cmd":"npm install cache-manager-ioredis","lang":"bash","label":"npm"},{"cmd":"yarn add cache-manager-ioredis","lang":"bash","label":"yarn"},{"cmd":"pnpm add cache-manager-ioredis","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core caching abstraction layer.","package":"cache-manager","optional":false},{"reason":"Underlying Redis client library.","package":"ioredis","optional":false}],"imports":[{"note":"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`.","wrong":"const redisStore = require('cache-manager-ioredis');","symbol":"redisStore","correct":"import redisStore from 'cache-manager-ioredis';"},{"note":"The `caching` function is a named export from `cache-manager` in newer versions, though older examples might show it differently.","wrong":"const cacheManager = require('cache-manager'); const { caching } = cacheManager;","symbol":"caching","correct":"import { caching } from 'cache-manager';"},{"note":"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.","symbol":"redisClient","correct":"const redisClient = redisCache.store.getClient();"}],"quickstart":{"code":"import { caching } from 'cache-manager';\nimport redisStore from 'cache-manager-ioredis';\n\nconst redisCache = caching({\n  store: redisStore,\n  host: 'localhost',\n  port: 6379,\n  password: process.env.REDIS_PASSWORD ?? 'XXXXX', // Use environment variable for security\n  db: 0,\n  ttl: 600\n});\n\nconst redisClient = redisCache.store.getClient();\n\nredisClient.on('error', (error) => {\n  console.error('Redis connection error:', error);\n  // Implement robust error handling, e.g., logging, alerts, or graceful degradation\n});\n\nconst ttl = 5;\n\nredisCache.set('foo', 'bar', { ttl: ttl }, (err) => {\n  if (err) {\n    console.error('Failed to set cache:', err);\n    return;\n  }\n  console.log('Key \"foo\" set.');\n\n  redisCache.get('foo', (err, result) => {\n    if (err) {\n      console.error('Failed to get cache:', err);\n      return;\n    }\n    console.log('Retrieved \"foo\":', result);\n\n    redisCache.del('foo', (err) => {\n      if (err) console.error('Failed to delete cache:', err);\n      else console.log('Key \"foo\" deleted.');\n    });\n  });\n});\n\nfunction getUser(id, cb) {\n  setTimeout(() => {\n    console.log(\"Returning user from slow database.\");\n    cb(null, { id: id, name: 'Bob' });\n  }, 100);\n}\n\nconst userId = 123;\nconst key = `user_${userId}`;\n\nredisCache.wrap(key, (cb) => {\n  getUser(userId, cb);\n}, { ttl: ttl }, (err, user) => {\n  if (err) console.error('Wrap operation failed:', err);\n  else console.log('Wrapped user:', user);\n});","lang":"javascript","description":"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."},"warnings":[{"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.","message":"The 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.","severity":"breaking","affected_versions":">=1.0.1"},{"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.","message":"The `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.","severity":"gotcha","affected_versions":">=2.1.0"},{"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.","message":"Redis 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.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"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.","cause":"The application could not resolve the hostname or connect to the Redis server at the specified host and port.","error":"Error: getaddrinfo ENOTFOUND localhost:6379"},{"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, ... })`.","cause":"The `store` option passed to `cacheManager.caching` is not a valid cache store instance (e.g., `redisStore` was not imported correctly or initialized improperly).","error":"TypeError: store.set is not a function"},{"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.","cause":"The Redis server requires a password, but none was provided in the `cache-manager-ioredis` configuration.","error":"Redis connection to 127.0.0.1:6379 failed - NOAUTH Authentication required."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":""}