您的位置:首页 > 数据库 > Redis

Redis源码分析系列一:main函数分析

2013-10-16 00:00 381 查看
学习redis,首先要找到入口函数main,位置位于Redis.c文件中。

下面是对于main函数的分析,会分为若干次进行分析,每次分析可能篇幅不长,我不喜欢太长的段落文章。

另外由于个人的习惯,会稍微改一点代码风格及变量赋值,阅读时请自我辨别,基本上不影响对代码的使用。

int main(int argc, char **argv)
{
//辛苦的码农生活从这里起航

struct timeval tv;//定义一个时间变量,以本人为例,时间为2013-10-16 21:02

/* 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_thread_safe为1

zmalloc_set_oom_handler(redisOutOfMemoryHandler);//设置zmalloc_oom_handler

srand(time(NULL)^getpid());//散布种子,取随机数使用

gettimeofday(&tv,NULL);//设置tv为当前时间

dictSetHashFunctionSeed(tv.tv_sec^tv.tv_usec^getpid());
//设置dict_hash_function_seed

server.sentinel_mode = checkForSentinelMode(argc,argv);
//确实是否为哨兵模式

//到此为止,比较简单,也没有什么需要注意的地方。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Redis