1. redis, as a memory database, needs to store a large amount of user data, but the data stored in redis is stored in the memory. Due to power failure or downtime, memory data will certainly be lost. To prevent data loss, usePersistence ModeTo back up memory data;
When redis memory contains data, there are two methods through its own policy. One isRDB Mode, One isAof (default); Data persistence based on the settings of its own mode;Both RDB and aof have their own persistent files;
When redis is restarted, it loads the persistent File Based on the name of the persistent file specified in the configuration file to restore memory data;
2. RDB mode:
2.1 features: RDB ModeRegularly persists data in the memory.If you are allowed to lose a small amount of data, the RDB mode is preferred, because the RDB mode isMemory Snapshot;Fast backup speed;
2.2 BACKUP command: (execute the redis BACKUP commandRun redis-CLI on the client.)
Save (manual backup) ------- will cause thread blocking. redis update is allowed only when the backup operation is complete;
Bgsave (background backup) ---- indicates running in the background without causing thread blocking. It will pick up time for data backup;
2.3 backup method:
Save 900 1 in 900 seconds, redis performs an update operation, then backup once
Save 300 10 in 300 seconds, redis performs 10 update operations, then backup once
Save 60 10000 in 60 seconds, redis performs 10000 update operations, then backup once
3. aof mode: (Real-time Data Backup is supported. This mode is equivalentRecords all user operations); Persistence files are saved in plaintext without encryption. (After aof mode is enabled, RDB mode does not take effect !!!)
3.1 features: Real-time Data Backup, good security, and slow persistence compared with the RDB mode;
Aof persistent files are large in size. It takes a long time to recover data;
3.2 aof persistence policy:
Appendfsync always ---------- each operation will be backed up
Appendfsync everysec ------- backup once per second
Appendfsync no ---------------- no operation
Redis persistence Policy