Introduction to the redis startup process

  • 2020-05-09 19:36:20
  • OfStack

1. Prepare the operating environment

* set oom handler, called when zmalloc failed to allocate memory
* initializes a random seed to generate a random number
* initializes the server parameter to the default value  
* create a mapping table for commands and handlers

2. Parse the command line parameters and loadServerConfig() parse the configuration file

* the configuration file overrides the parameters specified on the command line
* invalid configuration items or unreasonable configuration values can cause redis to fail to start properly

3. initServer() initializes the service

* install the signal handling function  
* create Shared objects, redis pre-allocated common objects for sharing, to save memory  
* adjust max open files according to the maxc lients configuration
*   creates the global db dictionary, with each db corresponding to one dict  
* listen on the network port and install the event handler  
* if aof is enabled, open aof file  
* create an serverCron timer

4. loadDataFromDisk() loads data from rdb or aof files

* load data errors (such as file format errors) will cause redis to fail to start properly
* during the loading process, redis is still able to process requests, but most of the requests respond to the -LOADING error

5. aeMain() begins an event loop to receive client requests

The event handler for the listening file descriptor is initialized to acceptTcpHandler, and the event handler for the newly established connection is set to readQueryFromClient. readQueryFromClient reads the request from the network connection, resolves the request parameters and processes them.


Related articles: