redis报错

来源:6-9 创建koa-seesion的redis存储store(2)

heZM

2019-05-10

ReplyError: ERR value is not an integer or out of range
      at parseError (D:\activity\github\node_modules\redis-parser\lib\parser.js:179:16)
      at parseType (D:\activity\github\node_modules\redis-parser\lib\parser.js:303:20)

key* 出来结果 已经保存成功了。网页显示Internal Server Error
cookies没有设置进去;
请问怎么解决?
完整的session-store在这里,更换为老师的就可以了。对比不出问题在哪里。


function  getRedisSessionID( sid ) {
    return `ssid:${sid}`
}
 class RedisSessionStore{

    constructor(client){
        this.client=client;
    }

    /**
     *获取redis存储的数据
     * @param sid {Number}
     * @returns {Promise.<void>}
     */
    async get(sid){
        console.log('get',sid)
        const  id=getRedisSessionID(sid);
        const data=await this.client.get(id);
        if(!data){
            return null;
        }
        try{
            const result=JSON.parse(data);
            return result;
        }catch (err){
            console.log(err)
        }
    }

    /**
     *
     * @param sid
     * @param sess
     * @param ttl {Number} 过期时间,单位-秒
     * @returns {Promise.<void>}
     */
    async set(sid,sess,ttl){
        console.log('setResis',sid,sess,ttl)
        const id=getRedisSessionID(sid)
        if(typeof ttl ==='number'){
            ttl=Math.ceil(ttl/1000);
        }
        try {
            console.log(sess)
            const sessStr=JSON.stringify(sess);
            console.log("sessStr",sessStr)
            if(ttl){
                await this.client.setex(id,ttl,sessStr)
            }else{
                await this.client.set(id,sessStr)
            }
        }catch (err){
            console.log(err)
        }


        await this.client.setex(sid,sess,ttl)
    }
    async destroy(sid){
        console.log('删除',sid)
        const id =getRedisSessionID(sid);
        await this.client.del(id)
    }
}
module.exports=RedisSessionStore;
写回答

2回答

Jokcy

2019-05-13

所以你报错的地方是具体写了什么代码?

0
6
Jokcy
回复
qq_我的心向大海_ckuGNU
这是一个插件的api啊,他提供我们api我们用,这是约定。如果要知道它里面做了什么,我们只能去看他的源码了。
2019-05-17
共6条回复

heZM

提问者

2019-05-10

"redis-parser": "^3.0.0",

另外尝试node直接调用redis进行存储读取,都是可以的//img.mukewang.com/szimg/5cd5363e0001406009920221.jpg

//img.mukewang.com/szimg/5cd5364c0001810305950169.jpg

0
0

全栈进阶课程 React16.8+Next.js+Koa2一步到位开发Github

学习React/Next.js服务端渲染SSR同构设计方案,理解OAuth登录体系的实现原理

651 学习 · 311 问题

查看课程