相关文章:
RDB 和 AOF 各有其优缺点,那么有没有一种能够结合两种的混合模式,即以 RDB 作为全量备份,AOF 作为增量备份,来提高备份效率,答案是肯定的,这就是 Redis 4.0 之后推出的 RDB-AOF 混合持久化模式,其作为默认配置来使用
一、RDB-AOF 相关配置
-
aof-use-rdb-preamble
# When rewriting the AOF file, Redis is able to use an RDB preamble in the # AOF file for faster rewrites and recoveries. When this option is turned # on the rewritten AOF file is composed of two different stanzas: # # [RDB file][AOF tail] # # When loading Redis recognizes that the AOF file starts with the "REDIS" # string and loads the prefixed RDB file, and continues loading the AOF # tail. aof-use-rdb-preamble yes
-
当 aof-use-rdb-preamble 设置为 yes 时,表示开启 RDB-AOF 混合持久化模式
-
在该模式下,AOF 重写产生的文件将同时包含 RDB 格式的内容和 AOF 格式的内容,该文件的前半段是 RDB 格式的全量数据,而后半段是 Redis 命令格式的增量数据
-
二、归纳总结
-
RDB 做全量持久化,AOF 做增量持久化
-
由于 RDB 是间隔一段时间后才会进行持久化,在此期间内如果 Redis 服务出现问题,则会丢失这一段时间内的数据,因此需要 AOF 来配合使用
-
在 Redis 重启时,会使用 BGSAVE 命令生成的 RDB 文件来重新构建内容,再使用 AOF 来重新执行近期的写指令,来实现数据的完整恢复