-1

What does the error mean? I just need to return the value I get from the redis command.

int getReply(char* result)
{
   redisContext *c;
   redisReply *reply;

   c = redisConnect((char*)"127.0.0.2", 6379);
   reply = redisCommand(c,"GET %s", "somekey");
   if (reply->str != NULL)
   {
       result = strdup(reply->str); 
       strerror(errno); // <-------- 'Operation now in progress'. result = null
   }

   freeReplyObject(reply);

   reply = redisCommand(c, "QUIT");
   printf("Disconnecting redis: %s\n", reply->str);

   freeReplyObject(reply);

   return 0;  
}

This happens even if I slowly step through it with the debugger (one would assume that any blocking action has long finished then). Redis specific error strings are empty, reply->str has the correct string that I want.

Blub
  • 13,014
  • 18
  • 75
  • 102

2 Answers2

1

There's an error only when strdup returns NULL.

I think you want

       result = strdup(reply->str); 
       if (!result) strerror(errno);
pmg
  • 106,608
  • 13
  • 126
  • 198
0

Okay for everyone following up on this: This is my bad, I need to pass in the address of a pointer, otherwise it will just pass in the value. So do it like this:

int getReply(char** result)
{
  *result = "yes";
}
Blub
  • 13,014
  • 18
  • 75
  • 102