背景
数据量大,mysql语句多,mysql查询慢,使用redis进行缓存
egg.js的redis使用
1.使用插件egg-redis
npm install egg-redis
2.配置
config.redis = {
client: {
port: '0007',
host: 'xxxx.redis.rds.aliyuncs.com', // Redis host
password: 'xxxzzzzxxxx',
db: 1
}
};
3.使用
ctx.app.redis.set('foo', 'bar','EX', 60 * 60 * 2);// 2小时后过期
ctx.app.redis.get('foo' );