Skip to content

Commit

Permalink
Change order independant push logic to not change behavior.
Browse files Browse the repository at this point in the history
Since redisGetReplyFromReader is exposed in a header file, we probably
shouldn't modify how it behaves in any way.  For this reason, handle the
changed logic in an internal static helper method.
  • Loading branch information
michael-grunder committed Apr 2, 2021
1 parent 6204182 commit dfa33e6
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions hiredis.c
Original file line number Diff line number Diff line change
Expand Up @@ -1005,14 +1005,23 @@ static int redisHandledPushReply(redisContext *c, void *reply) {
return 0;
}

/* Internal helper function to try and get a reply from the reader,
* or set an error in the context otherwise. */
/* Get a reply from our reader or set an error in the context. */
int redisGetReplyFromReader(redisContext *c, void **reply) {
if (redisReaderGetReply(c->reader, reply) == REDIS_ERR) {
__redisSetError(c,c->reader->err,c->reader->errstr);
return REDIS_ERR;
}

return REDIS_OK;
}

/* Internal helper to get the next reply from our reader while handling
* any PUSH messages we encounter along the way. This is separate from
* redisGetReplyFromReader so as to not change its behavior. */
static int redisNextInBandReplyFromReader(redisContext *c, void **reply) {
do {
if (redisReaderGetReply(c->reader,reply) == REDIS_ERR) {
__redisSetError(c,c->reader->err,c->reader->errstr);
if (redisGetReplyFromReader(c, reply) == REDIS_ERR)
return REDIS_ERR;
}
} while (redisHandledPushReply(c, *reply));

return REDIS_OK;
Expand All @@ -1023,7 +1032,7 @@ int redisGetReply(redisContext *c, void **reply) {
void *aux = NULL;

/* Try to read pending replies */
if (redisGetReplyFromReader(c,&aux) == REDIS_ERR)
if (redisNextInBandReplyFromReader(c,&aux) == REDIS_ERR)
return REDIS_ERR;

/* For the blocking context, flush output buffer and read reply */
Expand All @@ -1039,7 +1048,7 @@ int redisGetReply(redisContext *c, void **reply) {
if (redisBufferRead(c) == REDIS_ERR)
return REDIS_ERR;

if (redisGetReplyFromReader(c,&aux) == REDIS_ERR)
if (redisNextInBandReplyFromReader(c,&aux) == REDIS_ERR)
return REDIS_ERR;
} while (aux == NULL);
}
Expand Down

0 comments on commit dfa33e6

Please sign in to comment.