标签:nts conf max block 消息 void 启动过程 char ESS
一. 入口
int main(int argc, char **argv)
二. main()处理
1. server配制初始化
//各种配制初始化
void initServerConfig(void)
//redis命令初始化, server.commands就是在这里初始化的
populateCommandTable(void)
2. 加载配制
//加载配制文件
void loadServerConfig(char *filename, char *options)
//加载配制上面方法生成的配制字符串
loadServerConfigFromString(char *config)
3. server初始化
void initServer(void)
//通知消息静态数据初始化
createSharedObjects()
//最大可打开文件设置
adjustOpenFilesLimit()
//事件监听器
server.el = aeCreateEventLoop(server.maxclients+CONFIG_FDSET_INCR);
//db内存初始化
server.db = zmalloc(sizeof(redisDb)*server.dbnum);
//tcp监听端口初始化
listenToPort(server.port,server.ipfd,&server.ipfd_count)
server.sofd = anetUnixServer(server.neterr,server. server.unixsocketperm, server.tcp_backlog)
db初始化:
/* 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; }
计划任务和监听事件初始化:
/* 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. 加载数据
loadDataFromDisk()
5. server开启
aeSetBeforeSleepProc(server.el,beforeSleep);
//网络事件监听器启动
aeMain(server.el);
aeDeleteEventLoop(server.el);
标签:nts conf max block 消息 void 启动过程 char ESS
原文地址:https://www.cnblogs.com/ginkgo-leaf/p/9823392.html