当前位置: 首页 > 工具软件 > ioredis > 使用案例 >

koa-redis + ioredis

佴英奕
2023-12-01

const redisStore = require('koa-redis')
app.use(session({
//    配置cookie
    // key:'helios.co0kie',//浏览器 cookie 的名字
    // prefix: 'helios:sess:',     //redis key 的前缀
    // name: "session",	// cookie名称,默认为connect.sid
    key: 'weibo.sid',          //浏览器 cookie 的名字
    prefix: 'weibo:sess:',     //redis key 的前缀
    cookie: {
        path: '/',
        httpOnly: true,
        maxAge: 24  * 60 *  60  * 1000
    },
   
    store: redisStore({
        // all: `${REDIS_CONF.host}:${REDIS_CONF.port}`,
        host:`${REDIS_CONF.host}`,
        port:`${REDIS_CONF.port}`,
        // auth_pass:REDIS_CONF.pwd
    })
}))

----------------
Options

 * {Objec
 * t} client    redis client
* {String} host      redis connect host (without options.client)
* {Number} port      redis connect port (without options.client)
* {String} socket    redis connect socket (without options.client)
* {String} db        redis db
* {String} pass      redis password
* 
https://www.cnblogs.com/aibo/p/3852516.htm

ioredis

//创建客户端
const Redis=require('ioredis');
// const redis=new Redis({
//    host : '127.0.0.1',//安装好的redis服务器地址
//    port : 80, //端口
//    prefix : 'sam:',//存诸前缀
//    password: 'auth',
//    ttl : 60 * 60 * 23,//过期时间
//    db: 0
// });
const redisClient = new Redis({host:REDIS_CONF.host,port:REDIS_CONF.port,
  password:REDIS_CONF.pwd
});
 类似资料: