eggjs / egg-redis Goto Github PK
View Code? Open in Web Editor NEWredis plugin for egg
License: MIT License
redis plugin for egg
License: MIT License
password 和 db 的校验理论上可以去掉,修改如下: #39
app.redis.get('bar')获取不到实例,我已经在配置里写了client里面有两个对象实例
在请求接口 /test的时候,报错。redis的host、port以及password都是正确的,不知道是哪里出现了问题
egg-redis版本:^2.5.0
egg版本:^3
报错信息
2023-06-16 16:59:34,096 ERROR 60949 nodejs.ReplyError: NOAUTH Authentication required.
at parseError (/app/node_modules/redis-parser/lib/parser.js:179:12)
at parseType (/app/node_modules/redis-parser/lib/parser.js:302:14)
command: {"name":"info","args":[]}
pid: 60949
hostname: sz-user.local
router.js
'use strict';
/**
* @param {Egg.Application} app - egg application
*/
module.exports = app => {
const { router, controller } = app;
router.get('/test', controller.home.test);
router.get('/', controller.home.index);
};
controller/home.js
'use strict';
const { Controller } = require('egg');
class HomeController extends Controller {
async index() {
const { ctx } = this;
ctx.body = 'hi, egg';
}
async test() {
const { ctx, app } = this;
console.log('test start')
// set
await app.redis.set('foo', 'bar');
// get
ctx.body = await app.redis.get('foo');
}
}
module.exports = HomeController;
plugin.js
'use strict';
/** @type Egg.EggPlugin */
module.exports = {
// had enabled by egg
// static: {
// enable: true,
// }
redis: {
enable: true,
package: 'egg-redis'
}
};
config.default.js
/* eslint valid-jsdoc: "off" */
'use strict';
/**
* @param {Egg.EggAppInfo} appInfo app info
*/
module.exports = appInfo => {
/**
* built-in config
* @type {Egg.EggAppConfig}
**/
const config = exports = {};
// use for cookie sign key, should change to your own and keep security
config.keys = appInfo.name + '_1686821889236_483';
// add your middleware config here
config.middleware = [];
config.redis ={
// Redis: require('ioredis'),
client: {
cluster: true,
nodes: [{
host: '*.*.*.*.',
port: '*',
password: '*******',
db: 0,
// autoResubscribe: true
}]
},
}
// add your user config here
const userConfig = {
// myAppName: 'egg',
};
return {
...config,
...userConfig
};
};
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.