int readLogDataFromRedis(char readKey[50], struct logObj *logP)
{
printf("readkey=%s\n",readKey);
int DataCount = 0;
unsigned int j,n;
struct timeval timeout = { 1, 500000 }; // 1.5 seconds
redisContext* conn = redisConnectWithTimeout(redisServer, redisPort, timeout);
if (conn->err) {
printf("connection error:%s\n", conn->errstr);
redisFree(conn);
return 0;
}
redisReply* reply = (redisReply*)redisCommand(conn, readDB);
if (NULL == reply) {
redisFree(conn);
return 0;
}
if (!(reply->type == REDIS_REPLY_STATUS && strcasecmp(reply->str, "OK") == 0)) {
printf("Failed to execute command[%s].\n", readDB);
freeReplyObject(reply);
redisFree(conn);
return 0;
}
freeReplyObject(reply);
char cmd[50] = {0};
sprintf(cmd, "LRANGE %s 0 -1", readKey);
reply = (redisReply*)redisCommand(conn, cmd);
if (reply->type != REDIS_REPLY_ARRAY) {
printf("Failed to execute command[%s].\n",cmd);
freeReplyObject(reply);
redisFree(conn);
return 0;
}
//string str;
struct tempChar *tChar, *tCharBuf;
tChar = (struct tempChar*)malloc(sizeof(struct tempChar)*logCount);
memset(tChar, 0, sizeof(struct tempChar)*logCount);
tCharBuf = tChar;
for (j = 0; j < reply->elements; ++j) {
redisReply* childReply = reply->element[j];
if (childReply->type == REDIS_REPLY_STRING)
{
char *x = childReply->str;
//拼接原始數(shù)據(jù),壓縮后導(dǎo)出
strcat(tCharBuf[j].str, x);
strcat(tCharBuf[j].str, "\r");
int commasIndex = 0, commaeIndex = 0;
int col = 0;
strcat(x, "^");
for (n = 0; x[n] != '\0'; ++n)
{
if ('^' == x[n] || '\r' == x[n])
{
commaeIndex = n;
if (col == 0) strcpy(logP[DataCount].ev, subStr(x, commasIndex, commaeIndex));
if (col == 1) strcpy(logP[DataCount].cy, subStr(x, commasIndex, commaeIndex));
if (col == 2) logP[DataCount].v = atof(subStr(x, commasIndex, commaeIndex));
if (col == 3) strcpy(logP[DataCount].tp, subStr(x, commasIndex, commaeIndex));
if (col == 4) strcpy(logP[DataCount].ids, subStr(x, commasIndex, commaeIndex));
if (col == 5) logP[DataCount].cnt = atof(subStr(x, commasIndex, commaeIndex));
if (col == 6) strcpy(logP[DataCount].cg, subStr(x, commasIndex, commaeIndex));
if (col == 7) logP[DataCount].dt_fs = atof(subStr(x, commasIndex, commaeIndex));
if (col == 8) strcpy(logP[DataCount].wid, subStr(x, commasIndex, commaeIndex));
if (col == 9) strcpy(logP[DataCount].lp, subStr(x, commasIndex, commaeIndex));
if (col == 10) strcpy(logP[DataCount].ref, subStr(x, commasIndex, commaeIndex));
if (col == 11) logP[DataCount].sw = atoi(subStr(x, commasIndex, commaeIndex));
if (col == 12) logP[DataCount].sh = atoi(subStr(x, commasIndex, commaeIndex));
if (col == 13) strcpy(logP[DataCount].aid, subStr(x, commasIndex, commaeIndex));
if (col == 14) strcpy(logP[DataCount].agent, subStr(x, commasIndex, commaeIndex));
if (col == 15) strcpy(logP[DataCount].ga, subStr(x, commasIndex, commaeIndex));
if (col == 16) strcpy(logP[DataCount].sid, subStr(x, commasIndex, commaeIndex));
if (col == 17) strcpy(logP[DataCount].lid, subStr(x, commasIndex, commaeIndex));
if (col == 18) strcpy(logP[DataCount].gid, subStr(x, commasIndex, commaeIndex));
if (col == 19) strcpy(logP[DataCount].uid, subStr(x, commasIndex, commaeIndex));
if (col == 20) strcpy(logP[DataCount].gsid, subStr(x, commasIndex, commaeIndex));
if (col == 21) strcpy(logP[DataCount].ip, subStr(x, commasIndex, commaeIndex));
if (col == 22) logP[DataCount].dt = atof(subStr(x, commasIndex, commaeIndex));
commasIndex = n + 1;
col++;
}
}
if (strlen(logP[DataCount].aid)>0)
DataCount++;
col = 0; commasIndex = 0; commaeIndex = 0;
}
}
freeReplyObject(reply);
//轉(zhuǎn)換
char *src, *dst;
src = (char*)malloc(singleLen * logCount);
memset(src, 0, singleLen * logCount);
charAppendToStr(tCharBuf, logCount, src);
*(src - 1) = '\0';
//壓縮
char fileName[100] = {0};
sprintf(fileName, "%s/%s", filePath, readKey);
FILE *ofile = fopen(fileName, "wb");
qlz_state_compress *state_compress = (qlz_state_compress *)malloc(sizeof(qlz_state_compress));
int len, len2;
len = strlen(src);
dst = (char*)malloc(len + 400);
//寫(xiě)壓縮結(jié)果
len2 = qlz_compress(src, dst, len, state_compress);
fwrite(dst, len2, 1, ofile);
fclose(ofile);
printf("len2=%d,compress success!",len2);
reply = (redisReply*)redisCommand(conn, writeDB);
if (!(reply->type == REDIS_REPLY_STATUS && strcasecmp(reply->str, "OK") == 0)) {
printf("Failed to execute command[%s].\n", writeDB);
freeReplyObject(reply);
redisFree(conn);
return 0;
}
freeReplyObject(reply);
reply = (redisReply*)redisCommand(conn, "RPUSH toBeUpload_compress %s", readKey);
if (!(reply->type == REDIS_REPLY_INTEGER)) {
printf("Failed to execute command[%s].\n", "RPUSH toBeUpload_compress");
freeReplyObject(reply);
redisFree(conn);
return 0;
}
freeReplyObject(reply);
////刪除當(dāng)前key的數(shù)據(jù)
//reply = (redisReply*)redisCommand(conn, "del %s", readKey);
//freeReplyObject(reply);
if(src!=NULL){
free(src);
src=NULL;
}
if(dst!=NULL){
free(dst);
dst=NULL;
}
if(tChar!=NULL){
free(tChar);
tChar=NULL;
}
redisFree(conn);
return DataCount;
}
上面這段代碼之前是在windows上寫(xiě)的,運(yùn)行起來(lái)沒(méi)有任何問(wèn)題,現(xiàn)在環(huán)境改到centos7上面,重新編譯過(guò)了,運(yùn)行起來(lái)各種問(wèn)題,經(jīng)常出現(xiàn) “double free”或者“Segmentation fault”段錯(cuò)誤,仔細(xì)檢查了這段代碼,沒(méi)發(fā)現(xiàn)啥問(wèn)題,而且“Segmentation fault”這個(gè)錯(cuò)誤出現(xiàn)的一點(diǎn)規(guī)律都沒(méi)有,同樣的數(shù)據(jù)跑幾次可能其中一兩次會(huì)出現(xiàn)問(wèn)題,并且出現(xiàn)這個(gè)錯(cuò)誤問(wèn)題的位置還不一樣,有沒(méi)有大神解解惑的?
北大青鳥(niǎo)APTECH成立于1999年。依托北京大學(xué)優(yōu)質(zhì)雄厚的教育資源和背景,秉承“教育改變生活”的發(fā)展理念,致力于培養(yǎng)中國(guó)IT技能型緊缺人才,是大數(shù)據(jù)專業(yè)的國(guó)家
北大青鳥(niǎo)中博軟件學(xué)院創(chuàng)立于2003年,作為華東區(qū)著名互聯(lián)網(wǎng)學(xué)院和江蘇省首批服務(wù)外包人才培訓(xùn)基地,中博成功培育了近30000名軟件工程師走向高薪崗位,合作企業(yè)超4
中公教育集團(tuán)創(chuàng)建于1999年,經(jīng)過(guò)二十年潛心發(fā)展,已由一家北大畢業(yè)生自主創(chuàng)業(yè)的信息技術(shù)與教育服務(wù)機(jī)構(gòu),發(fā)展為教育服務(wù)業(yè)的綜合性企業(yè)集團(tuán),成為集合面授教學(xué)培訓(xùn)、網(wǎng)
達(dá)內(nèi)教育集團(tuán)成立于2002年,是一家由留學(xué)海歸創(chuàng)辦的高端職業(yè)教育培訓(xùn)機(jī)構(gòu),是中國(guó)一站式人才培養(yǎng)平臺(tái)、一站式人才輸送平臺(tái)。2014年4月3日在美國(guó)成功上市,融資1
曾工作于聯(lián)想擔(dān)任系統(tǒng)開(kāi)發(fā)工程師,曾在博彥科技股份有限公司擔(dān)任項(xiàng)目經(jīng)理從事移動(dòng)互聯(lián)網(wǎng)管理及研發(fā)工作,曾創(chuàng)辦藍(lán)懿科技有限責(zé)任公司從事總經(jīng)理職務(wù)負(fù)責(zé)iOS教學(xué)及管理工作。
浪潮集團(tuán)項(xiàng)目經(jīng)理。精通Java與.NET 技術(shù), 熟練的跨平臺(tái)面向?qū)ο箝_(kāi)發(fā)經(jīng)驗(yàn),技術(shù)功底深厚。 授課風(fēng)格 授課風(fēng)格清新自然、條理清晰、主次分明、重點(diǎn)難點(diǎn)突出、引人入勝。
精通HTML5和CSS3;Javascript及主流js庫(kù),具有快速界面開(kāi)發(fā)的能力,對(duì)瀏覽器兼容性、前端性能優(yōu)化等有深入理解。精通網(wǎng)頁(yè)制作和網(wǎng)頁(yè)游戲開(kāi)發(fā)。
具有10 年的Java 企業(yè)應(yīng)用開(kāi)發(fā)經(jīng)驗(yàn)。曾經(jīng)歷任德國(guó)Software AG 技術(shù)顧問(wèn),美國(guó)Dachieve 系統(tǒng)架構(gòu)師,美國(guó)AngelEngineers Inc. 系統(tǒng)架構(gòu)師。