[Redis] Persistence

I. Overview

All redis data is stored in memory. If persistence is not configured, all data will be lost after redis restarts. So turn on the redis persistence function and save the data to the disk. When the redis restarts, the data can be recovered from the disk.

There are two ways of redis persistence: 1.rdb snapshot persistence 2.aof log persistence


2. Detailed explanation

1.rdb snapshot persistence is to save in-memory data to disk in the form of snapshots



 

Configuration options for Rdb snapshots

 

save 900 1 // If there is 1 write in 900 , a snapshot will be generated

save 300 1000 // If there are 1000 writes within 300 seconds , a snapshot will be generated

save 60 10000 // If there are 10000 writes within 60 seconds , a snapshot will be generated

( These 3 options are blocked , then rdb is disabled )

 

stop-writes-on-bgsave-error yes // When an error occurs in the background backup process , will the main process stop writing ?

rdbcompression yes // Whether the exported rdb file is compressed

Rdbchecksum yes //  When importing rbd recovery data , do you want to check the integrity of rdb

dbfilename dump.rdb //Exported rdb file name

dir ./ // The placement path of rdb


2. Aof log persistence is to save each command to a text file




Configuration of Aof

appendonly no #Whether to open the aof log function

 

appendfsync always #Every command is synchronized to aof immediately . Safe , slow

appendfsync everysec #compromise , write 1 time per second

appendfsync no      # 写入工作交给操作系统,由操作系统判断缓冲区大小,统一写入到aof. 同步频率低,速度快,

 

 

no-appendfsync-on-rewrite yes: # 正在导出rdb快照的过程中,要不要停止同步aof

auto-aof-rewrite-percentage 100 #aof文件大小比起上次重写时的大小,增长率100%,重写

auto-aof-rewrite-min-size 64mb #aof文件,至少超过64M,重写

 


推荐一篇比较好的redis持久化文章

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325692914&siteId=291194637