Redis的持久化
持久化就是保持我们的数据不丢失,将数据通常保存在我们的硬盘中。在Redis中持久化的方式有两种,一种是快照持久化,一种是AOF持久化,各有各的优缺点,在项目中我们得根据实际的情况来选择具体的持久化方式。
这篇博客主要讲快照持久化(rdb文件)
快照持久化
也叫rdb持久化方式,通过拍摄快照方式进行数据的持久化,将某个时间内的数据存储到一个rdb的文件中,当再次启动redis服务时,会从这个rdb文件加载数据
配置快照持久化
默认持久化是开启的,在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 disable saving completely by commenting out all