Redis Boot Process

Source: Internet
Author: User



I. Entrance
int main (int argc, char **argv)



Two. Main () Processing
1. Server Configuration Initialization
Various configuration initialization
void Initserverconfig (void)
The Redis command is initialized, and Server.commands is initialized here.
Populatecommandtable (void)



2. Loading the configuration
Loading the configuration file
void Loadserverconfig (char *filename, char *options)
Load the compounding string generated by the method above
Loadserverconfigfromstring (char *config)



3. Server initialization
void Initserver (void)
Notification message static data initialization
Createsharedobjects ()
Maximum Open File Settings
Adjustopenfileslimit ()
Event Listener
Server.el = Aecreateeventloop (SERVER.MAXCLIENTS+CONFIG_FDSET_INCR);
DB Memory Initialization
server.db = Zmalloc (sizeof (REDISDB) *server.dbnum);
TCP Listener Port initialization
Listentoport (Server.port,server.ipfd,&server.ipfd_count)
SERVER.SOFD = Anetunixserver (server.neterr,server. Server.unixsocketperm, Server.tcp_backlog)
DB initialization:


 
 /* Create the Redis databases, and initialize other internal state. */ for (j = 0; j < server.dbnum; j++) {
        server.db[j].dict = dictCreate(&dbDictType,NULL);
        server.db[j].expires = dictCreate(&keyptrDictType,NULL);
        server.db[j].blocking_keys = dictCreate(&keylistDictType,NULL);
        server.db[j].ready_keys = dictCreate(&setDictType,NULL);
        server.db[j].watched_keys = dictCreate(&keylistDictType,NULL);
        server.db[j].eviction_pool = evictionPoolAlloc();
        server.db[j].id = j;
        server.db[j].avg_ttl = 0;
    }


    
Scheduled Tasks and Listener event initialization:


 
 /* Create the serverCron() time event, that‘s our main way to process
     * background operations. */ if(aeCreateTimeEvent(server.el, 1, serverCron, NULL, NULL) == AE_ERR) {
        serverPanic("Can‘t create the serverCron time event.");
        exit(1);
    } /* Create an event handler for accepting new connections in TCP and Unix
     * domain sockets. */ for (j = 0; j < server.ipfd_count; j++) { if (aeCreateFileEvent(server.el, server.ipfd[j], AE_READABLE,
            acceptTcpHandler,NULL) == AE_ERR)
            {
                serverPanic( "Unrecoverable error creating server.ipfd file event.");
            }
    } if (server.sofd > 0 && aeCreateFileEvent(server.el,server.sofd,AE_READABLE,
        acceptUnixHandler,NULL) == AE_ERR) serverPanic("Unrecoverable error creating server.sofd file event.");





4. Loading data
Loaddatafromdisk ()




5. Server Open
Aesetbeforesleepproc (Server.el,beforesleep);
Network Event Listener Boot
Aemain (Server.el);
Aedeleteeventloop (Server.el);






Redis Boot Process


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.