加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

深入redis内部之redis启动过程之二

发布时间:2020-12-16 04:45:14 所属栏目:安全 来源:网络整理
导读:接上文,继续分析代码 1. 设置线程安全模式 /*设置线程安全标识符为1*/ void zmalloc_enable_thread_safeness(void) { zmalloc_thread_safe = 1; 2. 内存溢出处理 zmalloc_set_oom_handler(redisOutOfMemoryHandler);/* 内存溢出的调用方法*/? ?void zmalloc

接上文,继续分析代码

1. 设置线程安全模式

/*设置线程安全标识符为1*/ void zmalloc_enable_thread_safeness(void) { zmalloc_thread_safe = 1;

2. 内存溢出处理

zmalloc_set_oom_handler(redisOutOfMemoryHandler);/* 内存溢出的调用方法*/? ?void zmalloc_set_oom_handler(void (*oom_handler)(size_t)) {

//调用下一级

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 bytesn",size); fflush(stderr); abort();}

3.生成hash seed

srand(time(NULL)^&^tv.tv_usec^getpid());

?3.1?time(?)函数头文件:#include?函数定义:time_t?time(time_t?*timer)功能描述:该函数返回从197011000000秒至今所经过的秒数。如果time_t?*timer非空指针,函数也会将返回值存到timer指针指向的内存。返回值:成功则返回秒数,失败则返回((time_t)-1)值,错误原因存于errno中。

3.2?getpid(取得进程识别码)表头文件 #include定义函数 pid_t getpid(void);函数说明 getpid()用来取得目前进程的进程识别码。

3.3?srand()函数?void srand(unsigned seed) 初始化随机数发生器。

3.4?gettimeofday()函数

#includeint gettimeofday(struct timeval*tv,struct timezone *tz )gettimeofday()会把目前的时间用tv 结构体返回,当地时区的信息则放到tz所指的结构中

3.5 设置hash seed

uint32_t dict_hash_function_seed = <span style="color: #0000ff;">void<span style="color: #000000;"> dictSetHashFunctionSeed(uint32_t seed) {
dict_hash_function_seed
=<span style="color: #000000;"> seed;
}

4. 检查是否sentime模式(集群的临时方案)

server.sentinel_mode = checkForSentinelMode( argc, **</span><span style="color: #0000ff;"&gt;if</span> (strstr(argv[<span style="color: #800080;"&gt;0</span>],<span style="color: #800000;"&gt;"</span><span style="color: #800000;"&gt;redis-sentinel</span><span style="color: #800000;"&gt;"</span>) != NULL) <span style="color: #0000ff;"&gt;return</span> <span style="color: #800080;"&gt;1</span><span style="color: #000000;"&gt;; </span><span style="color: #0000ff;"&gt;for</span> (j = <span style="color: #800080;"&gt;1</span>; j < argc; j++<span style="color: #000000;"&gt;) </span><span style="color: #0000ff;"&gt;if</span> (!strcmp(argv[j],<span style="color: #800000;"&gt;"</span><span style="color: #800000;"&gt;--sentinel</span><span style="color: #800000;"&gt;"</span>)) <span style="color: #0000ff;"&gt;return</span> <span style="color: #800080;"&gt;1</span><span style="color: #000000;"&gt;; </span><span style="color: #0000ff;"&gt;return</span> <span style="color: #800080;"&gt;0</span><span style="color: #000000;"&gt;;

}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读