接上文,继续分析代码
1. 设置线程安全模式
2. 内存溢出处理
//调用下一级
static void (*zmalloc_oom_handler)(size_t) = zmalloc_default_oom;
//最终调用
static void zmalloc_default_oom(size_t size) { fprintf(stderr,"zmalloc: Out of memory trying to allocate %zu bytes\n",size); fflush(stderr); abort();}
3.生成hash seed
3.1 time( )函数头文件:#include
3.2 getpid(取得进程识别码)表头文件 #include
3.3 srand()函数 void srand(unsigned seed) 初始化随机数发生器。
3.4 gettimeofday()函数
#include
3.5 设置hash seed
dict_hash_function_seed =<span style="color: #000000;"> seed;
}
4. 检查是否sentime模式(集群的临时方案)
</span><span style="color: #0000ff;">if</span> (strstr(argv[<span style="color: #800080;">0</span>],<span style="color: #800000;">"</span><span style="color: #800000;">redis-sentinel</span><span style="color: #800000;">"</span>) != NULL) <span style="color: #0000ff;">return</span> <span style="color: #800080;">1</span><span style="color: #000000;">;
</span><span style="color: #0000ff;">for</span> (j = <span style="color: #800080;">1</span>; j < argc; j++<span style="color: #000000;">)
</span><span style="color: #0000ff;">if</span> (!strcmp(argv[j],<span style="color: #800000;">"</span><span style="color: #800000;">--sentinel</span><span style="color: #800000;">"</span>)) <span style="color: #0000ff;">return</span> <span style="color: #800080;">1</span><span style="color: #000000;">;
</span><span style="color: #0000ff;">return</span> <span style="color: #800080;">0</span><span style="color: #000000;">;
}