Redis 如何在我的本地 Apache 服务器上保存数据,即使在重启和完全断电后也是如此?

How does Redis persist data on my local Apache server even after reboot and complete power down?

根据我的理解,如果我是 运行 本地 apache 开发服务器,Redis 会使用我从中收集 RAM 的内存。我尝试关闭我的电脑并断开电源线,但是当我重新启动我的电脑并再次测试我的测试网站时,我本地服务器开发网站上的 redis 数据仍然存在。我认为当我重新启动系统时 RAM 数据会被完全擦除,即使在我的本地开发环境中重新启动后,Redis 如何保留数据?谢谢! :)

Redis 仅从 RAM 中提供数据,但它提供两种持久化模式 RDB(快照持久化)和 AOF(变更日志持久化)。如果在您的 Redis 服务器上启用了任何一种持久性模式,那么您的数据将在重新启动之间持续存在。

您要检查的配置指令是:

  • 仅附加是
  • 保存

有关 Redis Persistence 的更多信息,请点击此处。

Redis 具有以 RDB 或 AOF 格式保存 Redis 数据的持久化选项(基本上将 Redis 数据保存到 file/log):

  • The RDB persistence performs point-in-time snapshots of your dataset at specified intervals.

  • The AOF persistence logs every write operation received by the server, that will be played again at server startup, reconstructing the original dataset. Commands are logged using the same format as the Redis protocol itself, in an append-only fashion. Redis is able to rewrite the log on background when it gets too big.

  • If you wish, you can disable persistence at all, if you want your data to just exist as long as the server is running.
  • It is possible to combine both AOF and RDB in the same instance. Notice that, in this case, when Redis restarts the AOF file will be used to reconstruct the original dataset since it is guaranteed to be the most complete.

此信息引用自 https://redis.io/topics/persistence,其中详细介绍了这些选项。

您可以从 Antirez 博客阅读更多内容:Redis Persistence Demystified