表达 mysql 会话
我找不到将 mysql 中存储的会话与express和node.js一起使用的好方法。有人有一些模块的技巧或实现这一目标的方法吗?
提前致谢
I cant find a good way to use sessions stored in mysql with express and node.js. Anyone has some tips of modules or a way to achieve this?
thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我创建了一个非常简单的 MySQL 会话存储,名为 connect-mysql-session。如果您已经有一个 MySQL 数据库并且想用它来持久化会话,那么这会很方便。通过 npm 安装它:
I've created a very simple MySQL session store called connect-mysql-session. This is handy if you already have a MySQL database handy and want to use it to persist sessions. Install it via npm with:
据我所知,目前有七个用于连接(express 在其上运行)的会话连接管理中间件:
express-session(与express 捆绑,使用 MemoryStore)
connect-redis https://github.com/visionmedia/connect-redis
connect-mongodb https://github.com/masylum/connect-mongodb
connect-couchdb https://github.com/tdebarochez/connect-couchdb
connect-memcached https://github.com/balor/connect-memcached
nstore-session https://github.com/creationix/nstore-session
cookie-sessions(在客户端 cookie 中存储会话)https://github.com/caolan/cookie-sessions
为了能够使用 Mysql 作为会话存储,有人需要为其创建一个连接中间件。 (connect-redis 只有 125 行,所以这可能不是一项艰巨的任务。)
There are currently seven session connection management middleware for connect (upon which express runs) that I am aware of:
express-session (bundled with express, uses MemoryStore)
connect-redis https://github.com/visionmedia/connect-redis
connect-mongodb https://github.com/masylum/connect-mongodb
connect-couchdb https://github.com/tdebarochez/connect-couchdb
connect-memcached https://github.com/balor/connect-memcached
nstore-session https://github.com/creationix/nstore-session
cookie-sessions (stores sessions in client-side cookies) https://github.com/caolan/cookie-sessions
In able to use Mysql as a session store, someone would need to create a connect middleware for it. (connect-redis is only 125 lines so it's probably not a herculean task.)