{"id":23081266,"url":"https://github.com/lagden/cache-redis","last_synced_at":"2025-08-15T23:31:21.191Z","repository":{"id":44708612,"uuid":"113377461","full_name":"lagden/cache-redis","owner":"lagden","description":"Using redis as cache","archived":false,"fork":false,"pushed_at":"2024-09-08T18:42:44.000Z","size":875,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-09-09T18:41:00.106Z","etag":null,"topics":["cache","cache-redis","lib","nodejs","redis","storage"],"latest_commit_sha":null,"homepage":null,"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/lagden.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-12-06T23:15:07.000Z","updated_at":"2024-09-08T18:42:41.000Z","dependencies_parsed_at":"2024-09-08T17:58:24.604Z","dependency_job_id":"5acbb4e2-2aac-4289-8717-60356e5deca0","html_url":"https://github.com/lagden/cache-redis","commit_stats":{"total_commits":82,"total_committers":4,"mean_commits":20.5,"dds":0.1097560975609756,"last_synced_commit":"50ab814aa0827c9a21c19340ab6b5e1d6f8fddb5"},"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lagden%2Fcache-redis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lagden%2Fcache-redis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lagden%2Fcache-redis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lagden%2Fcache-redis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lagden","download_url":"https://codeload.github.com/lagden/cache-redis/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229970738,"owners_count":18152711,"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-redis","lib","nodejs","redis","storage"],"created_at":"2024-12-16T13:50:39.828Z","updated_at":"2024-12-16T13:50:40.273Z","avatar_url":"https://github.com/lagden.png","language":"JavaScript","readme":"# cache-redis\n\n[![NPM version][npm-img]][npm]\n[![Node.js CI][ci-img]][ci]\n[![Coverage Status][coveralls-img]][coveralls]\n[![Snyk badge][snyk-img]][snyk]\n\n[npm-img]:         https://img.shields.io/npm/v/@tadashi/cache-redis.svg\n[npm]:             https://www.npmjs.com/package/@tadashi/cache-redis\n[ci-img]:          https://github.com/lagden/cache-redis/actions/workflows/nodejs.yml/badge.svg\n[ci]:              https://github.com/lagden/cache-redis/actions/workflows/nodejs.yml\n[coveralls-img]:   https://coveralls.io/repos/github/lagden/cache-redis/badge.svg?branch=main\n[coveralls]:       https://coveralls.io/github/lagden/cache-redis?branch=main\n[snyk-img]:        https://snyk.io/test/github/lagden/cache-redis/badge.svg\n[snyk]:            https://snyk.io/test/github/lagden/cache-redis\n\n\nMaking cache with Redis\n\n\n## Install\n\n```\n$ npm i @tadashi/cache-redis\n```\n\n\n## API\n\n### new Cache( \\[opts\\])\n\n| parameter | type        | required | default            | description       |\n| --------- | ----------- | -------- | ------------------ | ----------------- |\n| opts      | Object      | no       | [see below](#opts) | Options for configuring the cache. |\n\n\n#### opts\n\n| parameter      | type             | required | default        | description                             |\n| -------------- | ---------------- | -------- | -------------- | --------------------------------------- |\n| address        | String\\|String[] | no       | 127.0.0.1:6379 | The address of the Redis server.        |\n| namespace      | String           | no       | app            | A namespace for the cache keys.         |\n| redisOptions   | Object           | no       | -              | [See configuration options](https://redis.github.io/ioredis/interfaces/CommonRedisOptions.html) |\n\n\n### Cluster\n\nTo use `Cluster`, set addresses separated by commas or an array and set [clusterOptions](https://redis.github.io/ioredis/interfaces/ClusterOptions.html).\n\n```js\nimport Cache from '@tadashi/cache-redis'\n\nconst cache = new Cache({\n  address: '127.0.0.1:6379, 127.0.0.1:6380, 127.0.0.1:6381',\n  // or\n  address: ['127.0.0.1:6379', '127.0.0.1:6380', '127.0.0.1:6381'],\n  // and\n  redisOptions: {\n    clusterOptions: {\n      retryDelayOnClusterDown: 500,\n      // ...\n    }\n  }\n})\n```\n\n\n## Usage\n\n```js\nimport Cache from '@tadashi/cache-redis'\n\nconst _cache = new Cache({\n  redisOptions: {\n    keyPrefix: 'api'\n  },\n  namespace: 'example'\n})\n\nasync function find(key) {\n  try {\n    const cache = await _cache.get(key)\n    if (cache) {\n      return cache\n    }\n    const result = await getDataFromSomeWhere(key)\n    await _cache.set(key, result, 'PX', 3600)\n    return result\n  } catch (err) {\n    throw err\n  }\n}\n\n\nawait find('foo')\n// =\u003e data from getDataFromSomeWhere\n\nawait find('foo')\n// =\u003e data from cache\n```\n\n---\n\n\u003e [!IMPORTANT]  \n\u003e Buy me a coffee!  \n\u003e BTC: `bc1q7famhuj5f25n6qvlm3sssnymk2qpxrfwpyq7g4`\n\n\n## License\n\nMIT © [Thiago Lagden](https://github.com/lagden)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flagden%2Fcache-redis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flagden%2Fcache-redis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flagden%2Fcache-redis/lists"}