redis persistence persistence of AOF

AOF and RDB persistence by saving the database to record the different key-value pair database state, aof persistence is to record the state of the database by storing the write command redis server for execution. All commands are written AOF file are in Redis command requests protocol format to save.

1.AOF persistence to achieve

AOF persistence achieve additional commands can be divided (the append), the file is written, the file synchronization (sync) three steps.

1.1 instruction adding

When the end of the buffer aof_buf AOF persistence feature is turned on, the server after a write command is executed, the agreement will form the write command to be executed appended to the server status:

redisServer {struct 
// ... 
// AOF of buffer 
SDS aof_buf 
// ... 
};

E.g. redis> SET KEY VALUE

Then the server after executing this command set, the following agreement will be appended to the end aof_buf buffer:

*3\r\n$3\r\nSET\r\n$3\r\nKEY\r\n$5\r\nVALUE\r\n

Write and file synchronization 1.2 AOF

Redis command server process is an event loop (loop), this cycle of event files responsible for receiving client requests, and send commands to reply to the client, and the time the event is responsible for executing functions such as serverCron function require regular run.

Because the file server when processing events may write command, so that some of the content is appended to the aof_buf buffer inside, so the server before the end of each event loop, it will call flushAppendOnlyFile function, consider whether you need to

Aof_buf buffer contents are written and saved to a file inside AOF.

eventLoop DEF (): 
the while to true: 
// handle file event, send commands and receive commands request reply 
may be new content is added when processing command // request to aof_buf buffer 
processFileEvents () 
// processing time event 
processTimeEvents () 
/ / aof_buf consider whether the content is written and saved to a file inside AOF 
flushAppendOnlyFile ()

Option value appendfsync behavior flushAppendOnlyFile function configured by the server to determine the behavior of the various values ​​produced as follows:

The default value is appendfsync everysec, reference may redis.conf profile

 

 

Guess you like

Origin www.cnblogs.com/juin1058/p/11640705.html