Installations
npm install cache-manager-ioredis
Developer
dabroek
Developer Guide
Module System
CommonJS
Min. Node Version
>=6.0.0
Typescript Support
No
Node Version
12.15.0
NPM Version
6.13.4
Statistics
59 Stars
22 Commits
29 Forks
1 Watching
2 Branches
2 Contributors
Updated on 04 Jul 2024
Languages
JavaScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
9,855,068
Last day
-5.3%
10,687
Compared to previous day
Last week
-0.1%
61,243
Compared to previous week
Last month
-0%
264,732
Compared to previous month
Last year
8.3%
3,324,444
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
1
Dev Dependencies
4
IORedis store for node cache manager
Redis cache store for node-cache-manager.
This package is a almost identical to node-cache-manager-redis-store, but uses ioredis
instead of node_redis
. It aims to provide the most simple wrapper possible by just passing the configuration to the underlying ioredis
package.
Installation
1npm install cache-manager-ioredis --save
or
1yarn add cache-manager-ioredis
Usage Examples
See examples below on how to implement the IORedis cache store.
Single store
1var cacheManager = require('cache-manager'); 2var redisStore = require('cache-manager-ioredis'); 3 4var redisCache = cacheManager.caching({ 5 store: redisStore, 6 host: 'localhost', // default value 7 port: 6379, // default value 8 password: 'XXXXX', 9 db: 0, 10 ttl: 600 11}); 12 13// listen for redis connection error event 14var redisClient = redisCache.store.getClient(); 15 16redisClient.on('error', (error) => { 17 // handle error here 18 console.log(error); 19}); 20 21var ttl = 5; 22 23redisCache.set('foo', 'bar', { ttl: ttl }, (err) => { 24 if (err) { 25 throw err; 26 } 27 28 redisCache.get('foo', (err, result) => { 29 console.log(result); 30 // >> 'bar' 31 redisCache.del('foo', (err) => { 32 }); 33 }); 34}); 35 36function getUser(id, cb) { 37 setTimeout(() => { 38 console.log("Returning user from slow database."); 39 cb(null, { id: id, name: 'Bob' }); 40 }, 100); 41} 42 43var userId = 123; 44var key = `user_${userId}`; 45 46// Note: ttl is optional in wrap() 47redisCache.wrap(key, (cb) => { 48 getUser(userId, cb); 49}, { ttl: ttl }, (err, user) => { 50 console.log(user); 51 52 // Second time fetches user from redisCache 53 redisCache 54 .wrap(key, () => getUser(userId)) 55 .then(console.log) 56 .catch(err => { 57 // handle error 58 }); 59});
Multi-store
1var cacheManager = require('cache-manager'); 2var redisStore = require('cache-manager-ioredis'); 3 4var redisCache = cacheManager.caching({ store: redisStore, db: 0, ttl: 600 }); 5var memoryCache = cacheManager.caching({ store: 'memory', max: 100, ttl: 60 }); 6 7var multiCache = cacheManager.multiCaching([memoryCache, redisCache]); 8 9var userId2 = 456; 10var key2 = `user_${userId2}`; 11 12// Set value in all caches 13multiCache.set('foo2', 'bar2', { ttl: ttl }, (err) => { 14 if (err) { 15 throw err; 16 } 17 18 // Fetches from highest priority cache that has the key 19 multiCache.get('foo2', (err, result) => { 20 console.log(result); 21 22 // Delete from all caches 23 multiCache.del('foo2'); 24 }); 25}); 26 27// Note: ttl is optional in wrap 28multiCache.wrap(key2, (cb) => { 29 getUser(userId2, cb); 30}, (err, user) => { 31 console.log(user); 32 33 // Second time fetches user from memoryCache, since it's highest priority. 34 // If the data expires in the memory cache, the next fetch would pull it from 35 // the 'someOtherCache', and set the data in memory again. 36 multiCache.wrap(key2, (cb) => { 37 getUser(userId2, cb); 38 }, (err, user) => { 39 console.log(user); 40 }); 41});
Use Clustering (eg Amazon elasticache)
1var cacheManager = require('cache-manager'); 2var redisStore = require('cache-manager-ioredis'); 3 4// https://github.com/luin/ioredis#cluster 5var redisCache = cacheManager.caching({ 6 store: redisStore, 7 clusterConfig: { 8 nodes: [ 9 { 10 port: 6380, 11 host: '127.0.0.1' 12 }, 13 { 14 port: 6381, 15 host: '127.0.0.1' 16 } 17 ], 18 options: { 19 maxRedirections: 16 20 } 21 } 22});
Use an external Redis Instance
1var cacheManager = require('cache-manager'); 2var redisStore = require('cache-manager-ioredis'); 3var Redis = require('ioredis'); 4 5var redisInstance = new Redis({ 6 host: 'localhost', 7 port: 6379, 8 db: 0, 9}); 10 11var redisCache = cacheManager.caching({ 12 store: redisStore, 13 redisInstance: redisInstance 14});
Contribution
Want to help improve this package? We take pull requests.
License
The node-cache-manager-ioredis
is licensed under the MIT license.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
9 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
Reason
Found 1/18 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/run-tests.yml:1
- Info: no jobLevel write permissions found
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/run-tests.yml:22: update your workflow using https://app.stepsecurity.io/secureworkflow/dabroek/node-cache-manager-ioredis/run-tests.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/run-tests.yml:24: update your workflow using https://app.stepsecurity.io/secureworkflow/dabroek/node-cache-manager-ioredis/run-tests.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/run-tests.yml:29: update your workflow using https://app.stepsecurity.io/secureworkflow/dabroek/node-cache-manager-ioredis/run-tests.yml/master?enable=pin
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 third-party GitHubAction dependencies pinned
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 5 are checked with a SAST tool
Score
2.6
/10
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to cache-manager-ioredis
@types/cache-manager-ioredis
TypeScript definitions for cache-manager-ioredis
@tirke/node-cache-manager-ioredis
[![npm version](https://badge.fury.io/js/@tirke%2Fnode-cache-manager-ioredis.svg)](https://badge.fury.io/js/@tirke%2Fnode-cache-manager-ioredis)
@anchan828/nest-cache-manager-ioredis
cache-manager
Cache Manager for Node.js