日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

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

發(fā)布時(shí)間:2025/4/5 编程问答 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 深入redis内部之redis启动过程之二 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

接上文,繼續(xù)分析代碼

1. 設(shè)置線程安全模式

zmalloc_enable_thread_safeness();
/*
設(shè)置線程安全標(biāo)識(shí)符為1
*/
void zmalloc_enable_thread_safeness(void) {
zmalloc_thread_safe = 1;
}

2. 內(nèi)存溢出處理

zmalloc_set_oom_handler(redisOutOfMemoryHandler);
/*
內(nèi)存溢出的調(diào)用方法
*/
? ?void zmalloc_set_oom_handler(void (*oom_handler)(size_t)) {

? ? ? zmalloc_oom_handler = oom_handler;
? ? ? }

//調(diào)用下一級(jí)

static void (*zmalloc_oom_handler)(size_t) = zmalloc_default_oom;

//最終調(diào)用

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

srand(time(NULL)^getpid());gettimeofday(&tv,NULL);dictSetHashFunctionSeed(tv.tv_sec^tv.tv_usec^getpid());

?3.1?time(?)函數(shù)
頭文件:#include?<time.h>
函數(shù)定義:time_t?time(time_t?*timer)
功能描述:該函數(shù)返回從1970年1月1日00時(shí)00分00秒至今所經(jīng)過(guò)的秒數(shù)。如果time_t?*timer非空指針,函數(shù)也會(huì)將返回值存到timer指針指向的內(nèi)存。
返回值:成功則返回秒數(shù),失敗則返回((time_t)-1)值,錯(cuò)誤原因存于errno中。

3.2?getpid(取得進(jìn)程識(shí)別碼)
表頭文件 #include<unistd.h>
定義函數(shù) pid_t getpid(void);
函數(shù)說(shuō)明 getpid()用來(lái)取得目前進(jìn)程的進(jìn)程識(shí)別碼。

3.3?srand()函數(shù)?
void srand(unsigned seed) 初始化隨機(jī)數(shù)發(fā)生器。

3.4?gettimeofday()函數(shù)

#include<sys/time.h>
int gettimeofday(struct timeval*tv,struct timezone *tz )
gettimeofday()會(huì)把目前的時(shí)間用tv 結(jié)構(gòu)體返回,當(dāng)?shù)貢r(shí)區(qū)的信息則放到tz所指的結(jié)構(gòu)中

3.5 設(shè)置hash seed

static uint32_t dict_hash_function_seed = 5381;void dictSetHashFunctionSeed(uint32_t seed) {dict_hash_function_seed = seed; }

4. 檢查是否sentime模式(集群的臨時(shí)方案)

server.sentinel_mode = checkForSentinelMode(argc,argv); //根據(jù)啟動(dòng)的參數(shù)來(lái)檢查是否sentinel模式 /* Returns 1 if there is --sentinel among the arguments or if* argv[0] is exactly "redis-sentinel". */ int checkForSentinelMode(int argc, char **argv) {int j;if (strstr(argv[0],"redis-sentinel") != NULL) return 1;for (j = 1; j < argc; j++)if (!strcmp(argv[j],"--sentinel")) return 1;return 0; }

?

轉(zhuǎn)載于:https://www.cnblogs.com/davidwang456/p/3539773.html

總結(jié)

以上是生活随笔為你收集整理的深入redis内部之redis启动过程之二的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。