eggjs / egg

🥚 Born to build better enterprise frameworks and apps with Node.js & Koa
https://eggjs.org
MIT License
18.9k stars 1.82k forks source link

如何在Middleware获取Session #795

Closed AkashiX closed 7 years ago

atian25 commented 7 years ago

koa2 style: ctx.session koa1 style: this.session

发自我的 iPhone

在 2017年4月23日,15:26,M.Y.Akashi notifications@github.com 写道:

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

AkashiX commented 7 years ago

结果:{} 附加一下说明,这里我用了egg-session插件,session在登陆后存在memory。我的想法是在middleware做一个session filter,用于校验session是否存在。

AkashiX commented 7 years ago

Solved.

ngot commented 7 years ago

session默认存于客户端cookie,而不是内存

AkashiX commented 7 years ago

@ngot 我表述不完整,我参考egg-session把session存到memory里边。

atian25 commented 7 years ago

多进程的时候,存内存没意义啊。你应该用 https://github.com/eggjs/egg-session-redis 这类的插件。

dead-horse commented 7 years ago

多进程将 session 存内存就会导致你上面说的,session 找不到,真实线上运行的时候就懵逼了。

dead-horse commented 7 years ago

session 小存 cookie, session 很大存 redis,可以看看 egg-session-redis 插件