Express.js 与 sqlite 会话

发布于 2024-11-15 18:18:42 字数 606 浏览 0 评论 0 原文

我正在尝试使用 Express.js 设置一个轻量级应用程序。我想使用 Sqlite3 进行存储。

我需要某种会话管理,并尝试使用 Express 指南文档中描述的会话管理模块,如下所示(CoffeeScript)

g.app.configure -> 
  g.app.set 'views', "#{__dirname}/views"
  g.app.set 'view engine', 'jade'
  g.app.use g.express.bodyParser()
  g.app.use g.express.cookieParser()
  g.app.use g.express.session(secret:'cruel')
  g.app.use g.express.methodOverride()
  g.app.use g.app.router
  g.app.use g.express.static "#{__dirname}/public"

现在我想将会话存储在 sqlite3 中或以某种方式存储在项目路径中的文件中。

我发现的所有示例都使用不同类型的 NoSql 数据库。

任何人都可以阐明在哪里可以找到其他会话存储模块,甚至如何实现一个。

I am trying to setup a light weight application with Express.js. I would like to use Sqlite3 for storage.

I need some sort of session management and trying to use the session management module described in the Express guide document like so (CoffeeScript)

g.app.configure -> 
  g.app.set 'views', "#{__dirname}/views"
  g.app.set 'view engine', 'jade'
  g.app.use g.express.bodyParser()
  g.app.use g.express.cookieParser()
  g.app.use g.express.session(secret:'cruel')
  g.app.use g.express.methodOverride()
  g.app.use g.app.router
  g.app.use g.express.static "#{__dirname}/public"

Now I would like to store the sessions either in sqlite3 or as files in the project path somehow.

All examples I find use different kinds of NoSql-databases.

Could anyone shed some light on where to find other session store modules, or even how to implement one.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

失而复得 2024-11-22 18:18:42

我认为这 3 个链接对您有用:

http://senchalabs.github.com/ connect/middleware-session.html(在页面底部)

https://github.com/senchalabs/connect/blob/master/lib/middleware/session/memory.js

(connect 内置的会话的默认内存存储)

< a href="https://github.com/senchalabs/connect/wiki" rel="nofollow">https://github.com/senchalabs/connect/wiki(会话存储)

来自 Connect 指南(连接会话页面):

会话存储实现

每个会话存储都必须实现以下方法

* .get(sid, callback)
* .set(sid, session, callback)
* .destroy(sid, callback)

建议的方法包括但不限于:

* .length(callback)
* .clear(callback)

有关示例实现,请查看 connect-redis 存储库。

* param Object options
* returns Function

I think these 3 links will be useful for you:

http://senchalabs.github.com/connect/middleware-session.html (at the bottom of the page)

https://github.com/senchalabs/connect/blob/master/lib/middleware/session/memory.js

(the default memory store for session that connect has built-in)

https://github.com/senchalabs/connect/wiki (Session Stores)

From the Connect guide (Connect Session page):

Session Store Implementation

Every session store must implement the following methods

* .get(sid, callback)
* .set(sid, session, callback)
* .destroy(sid, callback)

Recommended methods include, but are not limited to:

* .length(callback)
* .clear(callback)

For an example implementation view the connect-redis repo.

* param Object options
* returns Function
短暂陪伴 2024-11-22 18:18:42

我发现所有示例都使用不同的
各种 NoSql 数据库。

许多 NoSQL 数据库的好处是它们非常易于安装。安装redis非常简单,并且会让你的网站速度更快(在内存数据库中通过光盘备份)...

谁能透露一下在哪里
查找其他会话存储模块

我使用 http://search.npmjs.org / http://github.com 搜索:

这是我很快发现的,但是在做时更彻底的搜索我相信您应该能够找到更多的会话实现。

或者甚至如何实现一个。

我认为您应该能够使用超市购物车,但您也可以使用此链接作为参考来实现自己的商店:

All examples I find use different
kinds of NoSql-databases.

The nice thing about a lot of those NoSQL databases is that they are really easy to install. Installing redis is very easy and will make your site a lot faster(in memory database backupped by disc)...

Could anyone shed some light on where
to find other session store modules

I found the following modules using http://search.npmjs.org / http://github.com searches:

This is what I found quickly, but when doing a more thoroughly search I believe you should be able to find even more session implementations.

or even how to implement one.

I think you should be able to use supermarket-cart, but you could also implement your own store by using this links as a reference:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文