antirez/hiredis — Issue #63: some problem about hredis c client using
Author: lylenical
Created: 2011-10-31 03:11:47+00:00
State: open

hi,
I got some problem about c client using when i was using function as redisCommand(c,'get key') ,the key is exists.At the beginning all goes right,but when the function was called fast some problem come.

This is my code:

CFKeyValueDB *ptclient;
void CFKeyValueDB::InitializeKeyValueDB(){
......
}

string CFKeyValueDB::get(string key){
redisReply *reply = (redisReply *)redisCommand(c,"GET %s",(char *)key.c_str());
try{
if(reply !=NULL){
string ret = reply->str;
freeReplyObject(reply) ;
LOG("get %s %s",(char *)key.c_str(),(char *)ret.c_str());
return ret;
}
}
catch(...){
LOG("get %s catch exception",(char *)key.c_str());
}
LOG("get %s fail",(char *)key.c_str());
return "",

}

this is the using code:

while(true){
string account = "test0001";
string key = "account@" + account;
ptclient->get(key);
}

In another thread i also call redisCommand(c,"ping")
exception:
the correct output is " get account@test0001 1"
but sometimes the output is " get account@test0001 PONG "
sometimes the output is "get account@test0001 get exception"

when i debug the client i found something:
at the file hiredis.c
function:redisReaderGetReply(redisReader r,void **reply)
at the last of the function:
/ Emit a reply when there is one. */
if(r->ridx == -1){
if(reply != NULL)
*reply = r->reply;
r->reply = NULL;
}
"*reply = r->reply;" was not called,
r->reply = NULL; called.

My client package is antriez-hiredis-7bc9f54. redis-server version:2.4.1.