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);
//确实是否为哨兵模式
//到此为止,比较简单,也没有什么需要注意的地方。
下面是对于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 源码分析系列1-main函数相关调用分析
- redis源码分析----main函数
- Redis源码分析系列十:acceptTcpHandler
- Redis源码分析系列三:initServerConfig下半部分
- Redis源码分析系列十六:processCommand研究
- Redis源码分析系列十五:processInlineBuffer
- Redis源码分析系列:引子
- SequoiaDB 系列之五 :源码分析之main函数
- Redis源码分析系列十四:processInputBuffer
- Tcpdump源码分析系列7:main函数
- Redis源码分析系列六:initserver中
- Tcpdump源码分析系列6: main函数研究
- Redis源码分析系列
- redis客户端Jedis源码分析系列——集合JedisByteHashMap
- Redis源码分析系列五:initServer上
- Tcpdump源码分析系列 5 : main函数研究
- Tcpdump源码分析系列4:main函数继续研究
- Tcpdump源码分析系列3:main函数继续研究
- Tcpdump源码分析系列2:main函数初探
- redis客户端Jedis源码分析系列——从缓存池中获取资源和销毁资源