gpt4 book ai didi

node.js - NodeJs服务器上存储数据可靠吗?

转载 作者:太空宇宙 更新时间:2023-11-03 23:55:17 25 4
gpt4 key购买 nike

我正在学习如何使用socket.io和nodejs。在 this answer他们解释了如何在 Nodejs 中将在线用户存储在数组中。这是在不将它们存储在数据库中的情况下完成的。这有多可靠?

  1. 存储在服务器中的数据可靠吗?数据是否始终保持其预期状态?
  2. 是否建议将数据存储在服务器中?我正在考虑一个有数百万用户的场景。
  3. 即使应用程序从不同位置提供服务,是否始终有一个服务器实例在运行?如果不是,在服务器中存储数据是否会导致不同服务器实例之间出现不一致?

最佳答案

恭喜您到目前为止的学习!我希望您玩得开心。

  1. Is data stored in the server reliable does the data always stay the way it is intended?

不,在服务器上存储数据通常不够可靠,除非您全面管理服务器。对于托管服务,永远不要在服务器上存储数据,因为管理服务器的一方很容易删除这些数据。

  1. Is it advisable to even store data in the server? I am thinking of a scenario where there are millions of users.

这根本不可取,您需要某种数据库。

  1. Is it that there is always one instance of the server running even when the app is served from different locations? If not, will storing data in the server bring up inconsistencies between the different server instances?

这种工作方式通常是服务器始终运行,并且在本地存储一些有关其配置的基本信息 - 扩展时,托管服务能够自动增加处理能力,并处理 load balancing在后台。每当服务器为您检索数据时,它都会从数据库请求数据,然后将其加载到 RAM(内存)中。在用户的示例中,您可以将用户数据存储在表或文档中( relational databasesdocument oriented database ),然后将它们加载到内存中以使用“函数”操作数据。

此外,要了解有关“数据不一致”问题的更多信息,请查找与数据库相关的并发,以及数据竞争条件

希望有帮助!

关于node.js - NodeJs服务器上存储数据可靠吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57509086/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com