redis源码分析----main函数

本文深入分析Redis的源码,主要聚焦在`main`函数中,包括初始化过程、配置文件处理、哨兵模式的检测及启动、内存管理、哨兵系统的初始化、守护进程设置以及数据加载等关键步骤。
摘要由CSDN通过智能技术生成
int main(int argc, char **argv) {
    struct timeval tv;


    /* We need to initialize our libraries, and the server configuration. */
#ifdef INIT_SETPROCTITLE_REPLACEMENT
    spt_init(argc, argv);
#endif
    setlocale(LC_COLLATE,"");
	/* 设置线程安全标志 */
    zmalloc_enable_thread_safeness();
	/* 设置内存管理函数 */
    zmalloc_set_oom_handler(redisOutOfMemoryHandler);
	/* 设置随机数种子 */
    srand(time(NULL)^getpid());
	/* 得到当前时间,下面设置哈希函数种子时会用到 */
    gettimeofday(&tv,NULL);
	/* 设置哈希函数种子 */
    dictSetHashFunctionSeed(tv.tv_sec^tv.tv_usec^getpid());
	/* 检查是否开启哨兵 */
    server.sentinel_mode = checkForSentinelMode(argc,argv);
	/* 初始化server变量 */
    initServerConfig();


    /* We need to init sentinel right now as parsing the configuration file
     * in sentinel mode will have the effect of populating the sentinel
     * data structures with master nodes to monitor. */
    if (server.sentinel_mode) {
		/* 设置哨兵相关配置,目前只有一个port选项,默认值为263
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值