Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some problem about hredis c client using #63

Closed
lylenical opened this issue Oct 31, 2011 · 1 comment
Closed

some problem about hredis c client using #63

lylenical opened this issue Oct 31, 2011 · 1 comment

Comments

@lylenical
Copy link

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.

@pietern
Copy link
Contributor

pietern commented Jul 11, 2013

This is likely a threading issue, where multiple threads are using the same connection.

I can't think of another way how you could get the string "PONG" inside an unrelated reply.

Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants