会话存储和数据库有什么区别 [英] What is the difference between a session store and database

查看:76
本文介绍了会话存储和数据库有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

从我发现的几乎所有资源中,我

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.

某些工具已内置用于内存中会话的存储,例如模块 express-session 带有默认的在内存中会话存储,但也有以下警告:

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:


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

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.

所以我搜索了可用的稳定的会话存储区,结果发现大多数名称是我听说过的数据库

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.

例如,这是会话存储列表我在GitHub上遇到的另一个

名称包括MongoDB,MySQL,SQLite,cassandra,firebase等,因此造成混乱。

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

问题是,会话存储是什么? / em>和数据库相同。 (我可以这样想-当我们使用数据库存储会话详细信息时,我们将其称为会话存储,但实际上它是一个数据库)

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..?

推荐答案

会话存储是将会话数据存储在其中的地方服务器。
在网络上通常由存储在客户端浏览器中的cookie标识。
因此,它使您的应用可以识别用户并保持登录状态。

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.

会话可以是内存,某些数据库,简单文件或任何其他内容

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.

不同会话存储之间的差异:


  • 每次重新启动应用程序时都会重置内存会话存储。同样也是最快的。

  • 数据库会话存储将通过重新启动应用程序
    变得安全。在某些时候,您将有很多会话对象
    可能需要清理。甚至可以从不同的应用程序访问存储在数据库中的同一会话。

这篇关于会话存储和数据库有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆