Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Session似乎经常失效,使用的Redis作为Session存储 #1488

Open
DickyNet opened this issue May 6, 2020 · 4 comments
Open

Session似乎经常失效,使用的Redis作为Session存储 #1488

DickyNet opened this issue May 6, 2020 · 4 comments

Comments

@DickyNet
Copy link

DickyNet commented May 6, 2020

DESC

ENV

OS Platform: unbuntu

Node.js Version: 12.0+

ThinkJS Version: 3.2.8

code

// your code here

error message

// your error message here

more description

// your detail description

我设置的Session保存在Redis中,设置的失效时间为1小时,经常不到1小时就Session失效,但是Redis中记录明明还在的,不知道为啥

@lizheming
Copy link
Contributor

看下 cookie 的过期时间,cookie 里会存 session id,服务端根据这个 id 关联 session

@DickyNet
Copy link
Author

DickyNet commented May 6, 2020

看下 cookie 的过期时间,cookie 里会存 session id,服务端根据这个 id 关联 session

adapter.js Session设置如下,cookie项下没有设置过期时间:

exports.session = {
  type: 'redis',
  common: {
    cookie: {
      name: constants.redis.cache_prefix,
      keys: ['werwer', 'werwer'],
      signed: true
    }
  },
  redis: {
    handle: redisSession,
    host: constants.redis.host,
    port: constants.redis.port,
    password: constants.redis.password,
    db: constants.redis.db,
    maxAge: constants.redis.maxAge
  }
};

@lizheming
Copy link
Contributor

自己上浏览器看下真实情况就清楚了,印象中不设置过期时间的话 cookie 都是会话级别的,关了浏览器就失效了。

@DickyNet
Copy link
Author

DickyNet commented May 6, 2020

刚试了,关了浏览器再进到是还是保持登录状态。我现在cookie里设置了与redis中一样的maxAge: constants.redis.maxAge项,我再观察下看看效果

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants