Redis EventsI. SUMMARY OF EVENTS
1 File Event: Redis is an event driver, Redis server connects to clients through sockets, handles command requests, generates command replies, and these processes become file events.
2 time Event: The Redis server performs a function call at a specified time or periodic time. Redis is a single process single-threaded model that executes file events and time events serially, such as write and sync Operations for persistent operations of AOF files, Redis processes execute File Event Processing Client command requests and then reply to command replies, then execution time events will execute the Servercron function, Call the Flushappendonlyfile function to write and sync the write command in the AOF_BUF buffer into the aof file. When the synchronization is placed. There are three options in the configuration file: Always: Sync every write
Everysec, the Sync no indicates that the system decides when to synchronize when the last sync time exceeds 1 seconds. Ii. documentation Incidents
Redis has developed its own network event processor based on the reactor model, known as a file event handler. The file event processor is divided into four components, sockets, I/O multiplexing programs, file event dispatcher, and event handlers. The file event processor runs single-threaded, using an I/O multiplexing program to listen for multiple sockets at the same time, and when the socket is ready to perform a connection response, read, write, and so on, the corresponding file event is generated to pass the socket to the event dispatcher. Because you are listening for multiple sockets, so multiple events may occur concurrently, I/O multiplexing technology puts all the sockets that generate file events into an orderly, synchronized queue, the dispatcher pulls the socket from the other end of the queue, and the corresponding processor is invoked based on the events associated with the socket.
2. File event handler:
Connection answering processor, command request processor, command reply Processor III, TIME event
Redis divides time events into timed events and recurring events, which are executed at specified times or in specified cycles. The time event has three main attributes: Id,when: The time that the event was executed, a UNIX timestamp, a function that called this function to handle the event when it was time.
The server places the time event in a unordered list, the time event is a node, the time event executor traverses the entire linked list, finds the time event that arrives, and invokes the corresponding event handler.
Servercron function: Normally the REDIS server has only one time event Servercron function. It allows Redis to periodically check and adjust its own resources and status, perform every 100 milliseconds, update the system cache time, clean up expired key-value pairs in the database (periodically delete policies), and close the client that failed the connection. AoF (Flushappendonfile writes after a file event, then determines when to synchronize according to the profile) or the RDB (save option) persistence operation.