{"id":26163960,"url":"https://github.com/dabroek/node-cache-manager-ioredis","last_synced_at":"2025-04-04T23:08:24.441Z","repository":{"id":20554280,"uuid":"90244839","full_name":"dabroek/node-cache-manager-ioredis","owner":"dabroek","description":"Redis store for node-cache-manager using IORedis.","archived":false,"fork":false,"pushed_at":"2023-01-09T01:59:34.000Z","size":217,"stargazers_count":57,"open_issues_count":17,"forks_count":29,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-04-14T21:50:49.209Z","etag":null,"topics":["cache","cache-manager","es2015","es6","ioredis","redis","redis-client","redis-store"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dabroek.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-04T09:21:03.000Z","updated_at":"2024-03-27T14:35:45.000Z","dependencies_parsed_at":"2023-01-12T03:30:43.853Z","dependency_job_id":null,"html_url":"https://github.com/dabroek/node-cache-manager-ioredis","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dabroek%2Fnode-cache-manager-ioredis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dabroek%2Fnode-cache-manager-ioredis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dabroek%2Fnode-cache-manager-ioredis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dabroek%2Fnode-cache-manager-ioredis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dabroek","download_url":"https://codeload.github.com/dabroek/node-cache-manager-ioredis/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247261607,"owners_count":20910108,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cache","cache-manager","es2015","es6","ioredis","redis","redis-client","redis-store"],"created_at":"2025-03-11T14:53:47.469Z","updated_at":"2025-04-04T23:08:24.424Z","avatar_url":"https://github.com/dabroek.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![build status](https://travis-ci.org/dabroek/node-cache-manager-ioredis.svg?branch=master)](https://travis-ci.org/dabroek/node-cache-manager-ioredis)\n[![coverage status](https://coveralls.io/repos/github/dabroek/node-cache-manager-ioredis/badge.svg?branch=master)](https://coveralls.io/github/dabroek/node-cache-manager-ioredis?branch=master)\n[![dependencies status](https://david-dm.org/dabroek/node-cache-manager-ioredis/status.svg)](https://david-dm.org/dabroek/node-cache-manager-ioredis)\n[![npm version](https://badge.fury.io/js/cache-manager-ioredis.svg)](https://badge.fury.io/js/cache-manager-ioredis)\n[![GitHub issues](https://img.shields.io/github/issues/dabroek/node-cache-manager-ioredis.svg)](https://github.com/dabroek/node-cache-manager-ioredis/issues)\n\nIORedis store for node cache manager\n==================================\n\nRedis cache store for [node-cache-manager](https://github.com/BryanDonovan/node-cache-manager). \n\nThis package is a almost identical to [node-cache-manager-redis-store](https://github.com/dabroek/node-cache-manager-redis-store), but uses [`ioredis`](https://github.com/luin/ioredis) instead of [`node_redis`](https://github.com/NodeRedis/node_redis). It aims to provide **the most simple wrapper possible** by just passing the configuration to the underlying [`ioredis`](https://github.com/luin/ioredis) package.\n\nInstallation\n------------\n\n```sh\nnpm install cache-manager-ioredis --save\n```\nor\n```sh\nyarn add cache-manager-ioredis\n```\n\nUsage Examples\n--------------\n\nSee examples below on how to implement the IORedis cache store.\n\n### Single store\n\n```js\nvar cacheManager = require('cache-manager');\nvar redisStore = require('cache-manager-ioredis');\n\nvar redisCache = cacheManager.caching({\n  store: redisStore,\n  host: 'localhost', // default value\n  port: 6379, // default value\n  password: 'XXXXX',\n  db: 0,\n  ttl: 600\n});\n\n// listen for redis connection error event\nvar redisClient = redisCache.store.getClient();\n\nredisClient.on('error', (error) =\u003e {\n  // handle error here\n  console.log(error);\n});\n\nvar ttl = 5;\n\nredisCache.set('foo', 'bar', { ttl: ttl }, (err) =\u003e {\n  if (err) {\n    throw err;\n  }\n\n  redisCache.get('foo', (err, result) =\u003e {\n    console.log(result);\n    // \u003e\u003e 'bar'\n    redisCache.del('foo', (err) =\u003e {\n    });\n  });\n});\n\nfunction getUser(id, cb) {\n  setTimeout(() =\u003e {\n    console.log(\"Returning user from slow database.\");\n    cb(null, { id: id, name: 'Bob' });\n  }, 100);\n}\n\nvar userId = 123;\nvar key = `user_${userId}`;\n\n// Note: ttl is optional in wrap()\nredisCache.wrap(key, (cb) =\u003e {\n  getUser(userId, cb);\n}, { ttl: ttl }, (err, user) =\u003e {\n  console.log(user);\n\n  // Second time fetches user from redisCache\n  redisCache\n    .wrap(key, () =\u003e getUser(userId))\n    .then(console.log)\n    .catch(err =\u003e {\n      // handle error\n    });\n});\n```\n\n### Multi-store\n\n```js\nvar cacheManager = require('cache-manager');\nvar redisStore = require('cache-manager-ioredis');\n\nvar redisCache = cacheManager.caching({ store: redisStore, db: 0, ttl: 600 });\nvar memoryCache = cacheManager.caching({ store: 'memory', max: 100, ttl: 60 });\n\nvar multiCache = cacheManager.multiCaching([memoryCache, redisCache]);\n\nvar userId2 = 456;\nvar key2 = `user_${userId2}`;\n\n// Set value in all caches\nmultiCache.set('foo2', 'bar2', { ttl: ttl }, (err) =\u003e {\n  if (err) {\n    throw err;\n  }\n\n  // Fetches from highest priority cache that has the key\n  multiCache.get('foo2', (err, result) =\u003e {\n    console.log(result);\n\n    // Delete from all caches\n    multiCache.del('foo2');\n  });\n});\n\n// Note: ttl is optional in wrap\nmultiCache.wrap(key2, (cb) =\u003e {\n  getUser(userId2, cb);\n}, (err, user) =\u003e {\n  console.log(user);\n\n  // Second time fetches user from memoryCache, since it's highest priority.\n  // If the data expires in the memory cache, the next fetch would pull it from\n  // the 'someOtherCache', and set the data in memory again.\n  multiCache.wrap(key2, (cb) =\u003e {\n    getUser(userId2, cb);\n  }, (err, user) =\u003e {\n    console.log(user);\n  });\n});\n```\n\n### Use Clustering (eg Amazon elasticache)\n\n```javascript\nvar cacheManager = require('cache-manager');\nvar redisStore = require('cache-manager-ioredis');\n\n// https://github.com/luin/ioredis#cluster\nvar redisCache = cacheManager.caching({\n  store: redisStore,\n  clusterConfig: {\n    nodes: [\n      {\n        port: 6380,\n        host: '127.0.0.1'\n      }, \n      {\n        port: 6381,\n        host: '127.0.0.1'\n      }\n    ],\n    options: {\n      maxRedirections: 16\n    }\n  }\n});\n```\n\n### Use an external Redis Instance\n\n```javascript\nvar cacheManager = require('cache-manager');\nvar redisStore = require('cache-manager-ioredis');\nvar Redis = require('ioredis');\n\nvar redisInstance = new Redis({\n  host: 'localhost',\n  port: 6379,\n  db: 0,\n});\n\nvar redisCache = cacheManager.caching({\n  store: redisStore,\n  redisInstance: redisInstance\n});\n```\n\nContribution\n------------\n\nWant to help improve this package? We take [pull requests](https://github.com/dabroek/node-cache-manager-ioredis/pulls).\n\n\nLicense\n-------\n\nThe `node-cache-manager-ioredis` is licensed under the MIT license.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdabroek%2Fnode-cache-manager-ioredis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdabroek%2Fnode-cache-manager-ioredis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdabroek%2Fnode-cache-manager-ioredis/lists"}