会话存储和数据库之间有什么区别

时间:2022-09-15 16:25:42

I've been trying to implement authentication and session management in a node.js application using socket.io.

我一直在尝试使用socket.io在node.js应用程序中实现身份验证和会话管理。

And from almost all the resources I found, I came across the term "session store".

从我发现的几乎所有资源中,我遇到了“会话商店”一词。

There are open source tools that handles sessions for us, but we have to provide them with a session store.

有一些开源工具可以为我们处理会话,但我们必须为它们提供会话存储。

Some tools has built in storage for sessions in memory, for example the module express-session comes with a default in memory session store, but also this warning:

一些工具内置存储器用于内存中的会话,例如模块express-session带有内存会话存储中的默认值,但也有此警告:

Warning The default server-side session storage, MemoryStore, is purposely not designed for a production environment. It will leak memory under most conditions, does not scale past a single process, and is meant for debugging and developing.

警告默认的服务器端会话存储MemoryStore故意不是为生产环境设计的。它会在大多数情况下泄漏内存,不会扩展到单个进程,并且用于调试和开发。

So I searched for the available stable session stores and it turns out that most of the names are databases that I've heard of.

所以我搜索了可用的稳定会话存储,事实证明大多数名称都是我听说过的数据库。

For example, here's a list of session stores and another one at GitHub that I've came across.

例如,这里是我遇到的会话商店列表和GitHub上的另一个会话商店列表。

The names include MongoDB, MySQL, SQLite, cassandra, firebase etc, hence the confusion.

名称包括MongoDB,MySQL,SQLite,cassandra,firebase等,因此存在混淆。

So the question is, are session stores and database the same..? (I can think of it like - when we're using the database for storing session details we call it session store but it's in fact a database)

所以问题是,会话存储和数据库是一样的吗? (我可以这样想 - 当我们使用数据库存储会话详细信息时,我们将其称为会话存储,但它实际上是一个数据库)

If not, how do they differ..?

如果没有,它们有何不同......?

2 个解决方案

#1


4  

Session store is a place where session data is being stored on server. On web its usually being identified by a cookie stored in clients browser. So it allows your app to identify user and keep him logged in for example.

会话存储是会话数据存储在服务器上的地方。在Web上,它通常由存储在客户端浏览器中的cookie标识。因此,它允许您的应用识别用户并让他保持登录状态。

Session can either be memory, some database, simple files, or any other place you can come up with to store session data.

会话可以是内存,某些数据库,简单文件,也可以是您可以用来存储会话数据的任何其他位置。

If you project uses some database, you can configure your session store to use the same database, to avoid having another database on server just for the purpose of session store.

如果项目使用某个数据库,则可以将会话存储配置为使用相同的数据库,以避免在服务器上有另一个数据库,仅用于会话存储。

Differences between different session stores:

不同会话商店之间的差异:

  • Memory session store is going to be reset on every app re-lauch. Also its fastest.
  • 内存会话存储将在每个应用程序重新启动时重置。也是最快的。
  • Database session store, is going to be safe with app re-lauch. And at some point you will have alot of session objects which you might want to clean up. And same session stored in database can be even accessed from different apps.
  • 数据库会话存储,对于app re-lauch来说是安全的。在某些时候,您将拥有许多您可能想要清理的会话对象。甚至可以从不同的应用程序访问存储在数据库中的相同会话。

#2


0  

Session store is a method of storing information about user as a session with unique identifier. It could be stored in memory or in database. Socket.io can utilize the same session (id) being used in express app by socket-express-session package, if I am not mistaken.

会话存储是一种将关于用户的信息存储为具有唯一标识符的会话的方法。它可以存储在内存或数据库中。如果我没有弄错的话,Socket.io可以利用socket-express-session包在express应用程序中使用的相同会话(id)。

You can then use session information to grant/restrict access, for example.

然后,您可以使用会话信息来授予/限制访问权限。

#1


4  

Session store is a place where session data is being stored on server. On web its usually being identified by a cookie stored in clients browser. So it allows your app to identify user and keep him logged in for example.

会话存储是会话数据存储在服务器上的地方。在Web上,它通常由存储在客户端浏览器中的cookie标识。因此,它允许您的应用识别用户并让他保持登录状态。

Session can either be memory, some database, simple files, or any other place you can come up with to store session data.

会话可以是内存,某些数据库,简单文件,也可以是您可以用来存储会话数据的任何其他位置。

If you project uses some database, you can configure your session store to use the same database, to avoid having another database on server just for the purpose of session store.

如果项目使用某个数据库,则可以将会话存储配置为使用相同的数据库,以避免在服务器上有另一个数据库,仅用于会话存储。

Differences between different session stores:

不同会话商店之间的差异:

  • Memory session store is going to be reset on every app re-lauch. Also its fastest.
  • 内存会话存储将在每个应用程序重新启动时重置。也是最快的。
  • Database session store, is going to be safe with app re-lauch. And at some point you will have alot of session objects which you might want to clean up. And same session stored in database can be even accessed from different apps.
  • 数据库会话存储,对于app re-lauch来说是安全的。在某些时候,您将拥有许多您可能想要清理的会话对象。甚至可以从不同的应用程序访问存储在数据库中的相同会话。

#2


0  

Session store is a method of storing information about user as a session with unique identifier. It could be stored in memory or in database. Socket.io can utilize the same session (id) being used in express app by socket-express-session package, if I am not mistaken.

会话存储是一种将关于用户的信息存储为具有唯一标识符的会话的方法。它可以存储在内存或数据库中。如果我没有弄错的话,Socket.io可以利用socket-express-session包在express应用程序中使用的相同会话(id)。

You can then use session information to grant/restrict access, for example.

然后,您可以使用会话信息来授予/限制访问权限。