Gathering detailed insights and metrics for egg-redis
Gathering detailed insights and metrics for egg-redis
Gathering detailed insights and metrics for egg-redis
Gathering detailed insights and metrics for egg-redis
npm install egg-redis
Module System
Unable to determine the module system for this package.
Min. Node Version
Typescript Support
Node Version
NPM Version
270 Stars
41 Commits
68 Forks
14 Watching
3 Branches
32 Contributors
Updated on 25 Sept 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-25.6%
620
Compared to previous day
Last week
-13.4%
4,670
Compared to previous week
Last month
5.7%
23,294
Compared to previous month
Last year
-84.1%
290,995
Compared to previous year
3
Redis client(support redis portocal) based on ioredis for egg framework
1$ npm i egg-redis --save
redis Plugin for egg, support egg application access to redis.
This plugin based on ioredis, if you want to know specific usage, you should refer to the document of ioredis.
Change ${app_root}/config/plugin.js
to enable redis plugin:
1exports.redis = { 2 enable: true, 3 package: 'egg-redis', 4};
Configure redis information in ${app_root}/config/config.default.js
:
Single Client
1config.redis = { 2 client: { 3 port: 6379, // Redis port 4 host: '127.0.0.1', // Redis host 5 password: 'auth', 6 db: 0, 7 }, 8}
Multi Clients
1config.redis = { 2 clients: { 3 foo: { // instanceName. See below 4 port: 6379, // Redis port 5 host: '127.0.0.1', // Redis host 6 password: 'auth', 7 db: 0, 8 }, 9 bar: { 10 port: 6379, 11 host: '127.0.0.1', 12 password: 'auth', 13 db: 1, 14 }, 15 } 16}
Sentinel
1config.redis = { 2 client: { 3 sentinels: [{ // Sentinel instances 4 port: 26379, // Sentinel port 5 host: '127.0.0.1', // Sentinel host 6 }], 7 name: 'mymaster', // Master name 8 password: 'auth', 9 db: 0 10 }, 11}
No password
Redis support no authentication access, but we are highly recommand you to use redis requirepass
in redis.conf
.
1 2$vim /etc/redis/redis.conf 3 4requirepass xxxxxxxxxx // xxxxxxxxxx is your password 5
Because it may be cause security risk, refer:
If you want to access redis with no password, use password: null
.
See ioredis API Documentation for all available options.
ioredis
versionegg-redis
using ioredis@4 now, if you want to use other version of ioredis, you can pass the instance by config.redis.Redis
:
1// config/config.default.js 2config.redis = { 3 Redis: require('ioredis'), // customize ioredis version, only set when you needed 4 client: { 5 port: 6379, // Redis port 6 host: '127.0.0.1', // Redis host 7 password: 'auth', 8 db: 0, 9 }, 10}
weakDependent
1config.redis = { 2 client: { 3 port: 6379, // Redis port 4 host: '127.0.0.1', // Redis host 5 password: 'auth', 6 db: 0, 7 weakDependent: true, // this redis instance won't block app start 8 }, 9}
In controller, you can use app.redis
to get the redis instance, check ioredis to see how to use.
1// app/controller/home.js 2 3module.exports = app => { 4 return class HomeController extends app.Controller { 5 async index() { 6 const { ctx, app } = this; 7 // set 8 await app.redis.set('foo', 'bar'); 9 // get 10 ctx.body = await app.redis.get('foo'); 11 } 12 }; 13};
If your Configure with multi clients, you can use app.redis.get(instanceName)
to get the specific redis instance and use it like above.
1// app/controller/home.js 2 3module.exports = app => { 4 return class HomeController extends app.Controller { 5 async index() { 6 const { ctx, app } = this; 7 // set 8 await app.redis.get('instance1').set('foo', 'bar'); 9 // get 10 ctx.body = await app.redis.get('instance1').get('foo'); 11 } 12 }; 13};
Before you start to use Redis Cluster, please checkout the document first, especially confirm cluster-enabled yes
in Redis Cluster configuration file.
In controller, you also can use app.redis
to get the redis instance based on Redis Cluster.
1 2// app/config/config.default.js 3 4exports.redis = { 5 client: { 6 cluster: true, 7 nodes: [{ 8 host: '127.0.0.1', 9 port: '6379', 10 family: 'user', 11 password: 'password', 12 db: 'db', 13 }, { 14 host: '127.0.0.1', 15 port: '6380', 16 family: 'user', 17 password: 'password', 18 db: 'db', 19 }] 20 }, 21}; 22 23// app/controller/home.js 24 25module.exports = app => { 26 return class HomeController extends app.Controller { 27 async index() { 28 const { ctx, app } = this; 29 // set 30 await app.redis.set('foo', 'bar'); 31 // get 32 ctx.body = await app.redis.get('foo'); 33 } 34 }; 35};
Please open an issue here.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 14/30 approved changesets -- score normalized to 4
Reason
0 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
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 More