Hiredis是Redis官方推出的一個用于連接redis資料庫的極簡C庫
GitHub地址:https://github.com/redis/hiredis ,測驗用的 版本是v1.0.0
redis和hiredis,官方并沒有提供windows版本,在GitHub的說明中也沒有windows平臺下使用的相關的介紹
編譯程序
1> githib下載v1.0.0版本 地址:https://github.com/redis/hiredis/tree/v1.0.0
2>vs創建靜態庫工程,添加hiredis目錄下*.c *.h檔案到vs工程,編譯工程
問題串列
1.編譯問題,sds.h檔案編譯報錯,在預編譯定義中添加inline=_inline

2.openssl庫依賴,hiredis支持建立ssl協議的安全連接,需要OpenSSL依賴庫,在此也可以跳過此功能,在vs工程中移除ssl.c,不編譯即可
3.hiredis.c檔案中"%zu" 修改為 "%lu",vs 不支持%zu size_t 格式化輸出
4.hiredis.c檔案中
cmd = hi_malloc(totlen+1); 申請的記憶體塊會被下面的for回圈寫越界,導致記憶體溢位,在函式外層,釋放cmd記憶體的時候崩潰掉,
修改方案為"cmd = hi_malloc(totlen+1+argc*3);"
1 /* Build the command at protocol level */ 2 cmd = hi_malloc(totlen+1); 3 if (cmd == NULL) 4 return -1; 5 6 pos = sprintf(cmd,"*%d\r\n",argc); 7 for (j = 0; j < argc; j++) { 8 len = argvlen ? argvlen[j] : strlen(argv[j]); 9 pos += sprintf(cmd+pos,"$%zu\r\n",len); 10 memcpy(cmd+pos,argv[j],len); 11 pos += len; 12 cmd[pos++] = '\r'; 13 cmd[pos++] = '\n'; 14 } 15 assert(pos == totlen); 16 cmd[pos] = '\0';
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/215427.html
標籤:其他
下一篇:判斷八字格局批處理
