koa2 redis

邢炯
2023-12-01
const Redis = require('ioredis')
const redis = {
    port: 6379,          // Redis port
    host: '**',   // Redis host
    prefix: 'pon:', //存诸前缀
    ttl: 60 * 60 * 23,  //过期时间   
    family: 4,
    db: 0
}
const newRedis = new Redis(redis)

function  get(key){
    return new Promise(function (resolve, reject) {
        newRedis.get(key, function (err, result) {  
            if(err) reject(err)
            console.log(result)
            resolve(result);
          });  
    })
};

//newRedis.set('a',"haha")
module.exports.newRedis = newRedis
module.exports.RedisGet = get

引用

const redis = require("../../common/redis")
const newRedis = redis.newRedis
const RedisGet = redis.RedisGet

router.get('/list', async (ctx, next) => {
    let rows = await RedisGet('/list')
    if(rows != null){
         console.log('rows = ',rows)
         ctx.response.body =rows;
         return;
    }
    let OuVersions = await OuVersion.findAll({});
    ctx.response.body ={Ou:OuVersions,} ;
    newRedis.set('/list',JSON.stringify({Ou:OuVersions,}))
});

 

转载于:https://www.cnblogs.com/cnchengv/p/10999832.html

 类似资料:

相关阅读

相关文章

相关问答