vipshop / hiredis-vip

Support redis cluster. Maintained and used at vipshop.
BSD 3-Clause "New" or "Revised" License
322 stars 173 forks source link

redisClusterAsyncCommand hangs after certain number of requests #66

Open ppnaik1890 opened 7 years ago

ppnaik1890 commented 7 years ago

Hi,

I am using hiredis-vip to get and set asychronously to/from redis. redisClusterAsyncCommand returns -1 after 28226 get request.

My code is as below:

void getCallback1(redisClusterAsyncContext *c, void *r, void *privdata) {
  redisReply *reply = (redisReply *) r;
  int j,ret;
  if (reply == NULL) return;
  printf("get data %s\n", reply->str);
  /* Disconnect after receiving the reply to GET */
  redisClusterAsyncDisconnect(c); 
}

int main (int argc, char **argv) {
 signal(SIGPIPE, SIG_IGN);
 int redis_ret,succ_count=0;
 struct event_base *base = event_base_new();

 redisClusterAsyncContext *c = redisClusterAsyncConnect("127.0.0.1:8000", HIRCLUSTER_FLAG_NULL);
 if (c->err) {
        /* Let *c leak for now... */
        printf("Error: %s\n", c->errstr);
        return 1;
 }

 redisClusterLibeventAttach(c,base);
 redisClusterAsyncSetConnectCallback(c, (redisConnectCallback *) connectCallback);
 redisClusterAsyncCommand(c, (redisClusterCallbackFn *) setCallback1, NULL, "SET %s %s", "foo", "hello world");
 redisClusterAsyncCommand(c, (redisClusterCallbackFn *) setCallback1, NULL, "SET %s %s", "hoo", "hello world1");

 event_base_dispatch(base);
 while(1){
    redis_ret = 2;
    while(redis_ret!=0){
        redis_ret = redisClusterAsyncCommand(c, (redisClusterCallbackFn *) getCallback1, NULL, "GET %d", 5);
        if(redis_ret<0){
                printf("Error: %s\n", c->errstr);
        //      redisClusterAsyncSetConnectCallback(c, (redisConnectCallback *) connectCallback);       
        redisClusterReset((redisClusterContext*)&c);
        event_base_dispatch(base);
        }
     }
     succ_count++;
     printf("redis msg is %d %d \n",redis_ret,succ_count);
     event_base_dispatch(base);
 }

The error printed is: Error: Cannot assign requested address

The code hangs after the first request if I do not do redisClusterAsyncDisconnect(c); in the get call back function.

Please help me resolve this issue.

Thanks, Priyanka

deep011 commented 6 years ago

Please see the asynchronous example: https://github.com/vipshop/hiredis-vip/wiki/Example-Asynchronous