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