| 502 | } |
| 503 | |
| 504 | void redisProcessCallbacks(redisAsyncContext *ac) { |
| 505 | redisContext *c = &(ac->c); |
| 506 | redisCallback cb = {NULL, NULL, 0, NULL}; |
| 507 | void *reply = NULL; |
| 508 | int status; |
| 509 | |
| 510 | while((status = redisGetReply(c,&reply)) == REDIS_OK) { |
| 511 | if (reply == NULL) { |
| 512 | /* When the connection is being disconnected and there are |
| 513 | * no more replies, this is the cue to really disconnect. */ |
| 514 | if (c->flags & REDIS_DISCONNECTING && hi_sdslen(c->obuf) == 0 |
| 515 | && ac->replies.head == NULL) { |
| 516 | __redisAsyncDisconnect(ac); |
| 517 | return; |
| 518 | } |
| 519 | |
| 520 | /* If monitor mode, repush callback */ |
| 521 | if(c->flags & REDIS_MONITORING) { |
| 522 | __redisPushCallback(&ac->replies,&cb); |
| 523 | } |
| 524 | |
| 525 | /* When the connection is not being disconnected, simply stop |
| 526 | * trying to get replies and wait for the next loop tick. */ |
| 527 | break; |
| 528 | } |
| 529 | |
| 530 | /* Send any non-subscribe related PUSH messages to our PUSH handler |
| 531 | * while allowing subscribe related PUSH messages to pass through. |
| 532 | * This allows existing code to be backward compatible and work in |
| 533 | * either RESP2 or RESP3 mode. */ |
| 534 | if (redisIsSpontaneousPushReply(reply)) { |
| 535 | __redisRunPushCallback(ac, reply); |
| 536 | c->reader->fn->freeObject(reply); |
| 537 | continue; |
| 538 | } |
| 539 | |
| 540 | /* Even if the context is subscribed, pending regular |
| 541 | * callbacks will get a reply before pub/sub messages arrive. */ |
| 542 | if (__redisShiftCallback(&ac->replies,&cb) != REDIS_OK) { |
| 543 | /* |
| 544 | * A spontaneous reply in a not-subscribed context can be the error |
| 545 | * reply that is sent when a new connection exceeds the maximum |
| 546 | * number of allowed connections on the server side. |
| 547 | * |
| 548 | * This is seen as an error instead of a regular reply because the |
| 549 | * server closes the connection after sending it. |
| 550 | * |
| 551 | * To prevent the error from being overwritten by an EOF error the |
| 552 | * connection is closed here. See issue #43. |
| 553 | * |
| 554 | * Another possibility is that the server is loading its dataset. |
| 555 | * In this case we also want to close the connection, and have the |
| 556 | * user wait until the server is ready to take our request. |
| 557 | */ |
| 558 | if (((redisReply*)reply)->type == REDIS_REPLY_ERROR) { |
| 559 | c->err = REDIS_ERR_OTHER; |
| 560 | snprintf(c->errstr,sizeof(c->errstr),"%s",((redisReply*)reply)->str); |
| 561 | c->reader->fn->freeObject(reply); |
no test coverage detected