Redis 是内存数据库,如果不将内存中的数据库状态保存到磁盘,那么一旦服务器进程退出会造成服务器中的数据库状态也会消失。所以 Redis 提供了数据持久化功能。Redis支持两种方式的持久化,一种是RDB方式;另一种是AOF(append-only-file)方式。两种持久化方式可以单独使用,也可以将这两种方式结合使用。
视频讲解如下:
Redis的数据持久化 |
---|
【赵渝强老师】Redis的数据持久化 |
这里重点讨论一下Redis的RDB数据持久化。RDB持久化是Redis默认的持久化方式。它是指在指定的时间间隔内将内存中的数据集快照写入磁盘,实际操作过程是fork一个子进程,先将数据集写入临时文件,写入成功后再替换之前的文件,并用二进制压缩存储。
视频讲解如下:
Redis的RDB数据持久化 |
---|
【赵渝强老师】Redis的RDB数据持久化 |
一、RDB持久化机制的工作流程
RDB执行快照的时机由以下参数决定:
# Save the DB to disk.
# save <seconds> <changes>
# Redis will save the DB if both the given number of seconds and the given
# number of write operations against the DB occurred.
# Snapshotting can be completely disabled with a single empty
# string argument as in following example: