redis - 如何让redis持久化

标签 redis

我使用 redis

我希望数据库是持久的,但是当我终止我的进程时,我注意到数据没有恢复。

例如,我有 100 个键和值。我的进程在 id = 26060 上运行。当我这样做时:

kill -9 26060

再次运行redis-server,所有的key都丢失了。

我检查了redis.conf中的相关定义,但没有找到任何东西。

如何让它持久化?

最佳答案

关于您的测试,如果您希望对其进行快照,则应等待 5 分钟后再终止该进程。

这是 Redis (2.8 - 3.0) 的默认配置:

################################ SNAPSHOTTING  ################################
#
# Save the DB on disk:
#
#   save <seconds> <changes>
#
#   Will save the DB if both the given number of seconds and the given
#   number of write operations against the DB occurred.
#
#   In the example below the behaviour will be to save:
#   after 900 sec (15 min) if at least 1 key changed
#   after 300 sec (5 min) if at least 10 keys changed
#   after 60 sec if at least 10000 keys changed
#
#   Note: you can disable saving completely by commenting out all "save" lines.
#
#   It is also possible to remove all the previously configured save
#   points by adding a save directive with a single empty string argument
#   like in the following example:
#
#   save ""

save 900 1
save 300 10
save 60 10000

有关持久性的一切都在 documentation 中进行了解释

保存数据的文件由以下配置选项定义:

# The filename where to dump the DB
dbfilename dump.rdb

# For default save/load DB in/from the working directory
# Note that you must specify a directory not a file name.
dir /var/lib/redis/

关于redis - 如何让redis持久化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30760026/

相关文章:

nosql - 无法使用 --pipe 进行 redis 批量插入

Haskell 守护进程无法从 Redis 中提取 `getAddrInfo`/`Too many open files` 错误

redis - lettuce redis brpop 命令

java - 使用 java 、Redis、Elastic Search 、Mongo 自动完成

redis - 增加默认内存和hash,设置redis的key limit

c# - Azure RedisCache 上的 SignalR 横向扩展 - 连接问题

redis - 如何在redis中获得2组的交集?

mysql - Deis 工作流支持非 12 因素服务

redis - 在安装 gitlab-shell 时遇到问题

c++ - Redis 中的消息包