Redis BGREWRITEAOF, redisbgrewriteaof
I was pitted by redis last night. After I got down and restarted, I waited for half an hour to start successfully. By discovering that the aof file was too large, previously, I did not know that this file can be optimized through BGREWRITEAOF.
The reference manual is as follows:
BGREWRITEAOF
Execute an AOF file rewriting operation. Rewriting creates a volume optimized version of the current AOF file.
Even if BGREWRITEAOF fails, no data is lost because the old AOF file is not modified before BGREWRITEAOF is successful.
The rewrite operation is only triggered when no other persistence work is executed in the background, that is:
- If the Redis sub-process is saving the snapshot, The AOF rewrite operation will be scheduled (scheduled), and the AOF rewrite will be executed after the save operation is complete. In this case, the BGREWRITEAOF returned value is stillOKBut an additional information is added, indicating that BGREWRITEAOF can be executed only after the save operation is complete. In Redis 2.6 or later versions, you can run the INFO command to check whether BGREWRITEAOF is scheduled.
- If another AOF file is being rewritten, BGREWRITEAOF returns an error, and the new BGREWRITEAOF request will not be scheduled for the next execution.
Starting from Redis 2.4, AOF rewrite is automatically triggered by Redis. BGREWRITEAOF is only used to manually trigger the rewrite operation.