持久化概念: 可以将数据写入到磁盘中,在服务器出现停机或者宕机;再次启动redis时,会将磁盘中的备份数据加载到内存中恢复使用
redis中有两种持久化的机制:
1、RDB(快照)
1.1、实现原理
redis是由C语言实现的,fork函数会把主线程复制一个子线程,子线程会把内存的数据依次遍历出来,存放到指定的二进制文件当中:dump.rdb
1.2、配置快照持久化
redis中的快照持久化默认是开启的,在redis.conf配置文件中有相关的配置选项
################################ 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 disabl