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存储在mysql中,当cookie过期了,怎么删除msyql中的session? #183

Open
tinytot1 opened this issue Sep 18, 2019 · 3 comments

Comments

@tinytot1
Copy link

You can store the session content in external stores (Redis, MongoDB or other DBs) by passing options.store with three methods (these need to be async functions):

get(key, maxAge, { rolling }): get session object by key
set(key, sess, maxAge, { rolling, changed }): set session object for key, with a maxAge (in ms)
destroy(key): destroy session for key

这里不能获取失效的key

@ysk2014
Copy link

ysk2014 commented Oct 24, 2019

方法1:
app.on('session:expired', ({ key, value, ctx }) => {store. destroy(key)})
方法2:
在store的get方法中判断是否过期,过期就删除

const stroe = {
    async get(key, maxAge, {rolling}) {
         let session = {/*mysql 查询*/};
         if (session._expire < Date.now()) {
            this. destroy(key)
            session = null
         }
         return session;
    }
}

@PleaseTryAgain
Copy link

@ysk2014
方法一好像cookie过期了也不会被触发

@ysk2014
Copy link

ysk2014 commented Nov 15, 2019

image
代码里是每次请求的时候都会去验证是否过期,你看看你的session对象中是否有_expire这个字段?

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

3 participants