Brief introduction:
Redis AOF is persisted, and every time that you receive changes to Redis data is logged to a AOF file, and data is not lost when the server is unexpectedly down or the Redis server is illegally shut down.
Data security can be achieved, but performance is affected.
1, modify the redis.conf
Shell > vim/usr/local/redis/redis.confdaemonize Yesport6379Timeout -loglevel Debugpidfile/usr/local/redis/logs/Redis.pidlogfile/usr/local/redis/logs/redis.logdatabases -#save the 1#save - Ten#save - 10000#rdbcompression yes#dbfilename dump.rdb## off RDB persistencedir/usr/local/redis/data/appendonly yesappendfilename appendonly.aofappendfsync everysec## turn on AOF persistence, define AOF file name, define the synchronization disk rule force sync per second no-appendfsync-on-rewrite Yesauto-aof-rewrite-percentage -Auto-aof-rewrite-min-Size 64mb## because the AOF attribute is to record each operation, when the client performs the same action, AOF also logs these same actions each time, then the AOF file increases continuously.
# # For this issue, you can use the rewrite feature of the aof file to resolve the growth of the aof file. When the aof file satisfies certain conditions, the AOF is rewritten, overwriting the data from the current in-memory database to a temporary aof file and replacing the original aof file after writing. # # no-appendfsync-on-The rewrite parameter indicates that the newly received write operation is not synchronized during the rewrite, is temporarily present in memory, and then written after rewriting, preventing conflicts with disk IO. # # Auto-aof-rewrite-The percentage parameter indicates that the AOF file growth rate is greater than this value and the AoF file is greater than the value of the following parameter, triggering aof rewrite## autoThe-aof-rewrite-min-size parameter indicates that the current aof file size is larger than this value
2. Test Redis AOF Persistence
Shell > redis-server/usr/local/redis/ls /usr/local/redis/data/appendonly.aof
# # Generate an empty file for. aof
Shell > redis-Cliredis127.0.0.1:6379>Set name Wangokredis127.0.0.1:6379>Get name"Wang"Redis127.0.0.1:6379>Set name1 Zhaookredis127.0.0.1:6379>Get name1"Zhao"Redis127.0.0.1:6379>Set name2 Lunokredis127.0.0.1:6379>Get name2"LUNs"Redis127.0.0.1:6379>Quitshell>Cat/usr/local/redis/data/appendonly.aof*2$6select$10*3$3set$4name$4Wang*3$3set$5name1$4Zhao*3$3set$5name2$3LUNs
# # Records every operation
Kill -9 'cat /usr/local/redis/logs/redis.pid '
# # Like testing an RDB, illegally shutting down Redis
Shell > redis-server/usr/local/redis/Redis.confshell> redis-Cliredis127.0.0.1:6379>Get name"Wang"Redis127.0.0.1:6379>Get name1"Zhao"Redis127.0.0.1:6379>Get name2"LUNs"Redis127.0.0.1:6379> Quit
# # Start Test keys/value are present.
# # is recommended to use AOF persistence while also using the RDB semi-persistent, AOF priority is higher than the RDB, that is, start the service is loaded AOF, after loading the RDB.
# # When the Redis server disk is broken, how is the data guaranteed not to be lost? Master/slave Way to solve!
Redis AOF Full Persistence