Change reply processing code to prepare for pub/sub

This commit is contained in:
Pieter Noordhuis 2010-12-31 11:27:32 +01:00
parent 2d53a6a711
commit 3ce8d5b08b
2 changed files with 17 additions and 2 deletions

16
async.c
View File

@ -247,12 +247,20 @@ void redisProcessCallbacks(redisAsyncContext *ac) {
break; break;
} }
/* Shift callback and execute it */ /* Even if the context is subscribed, pending regular callbacks will
assert(__redisShiftCallback(&ac->replies,&cb) == REDIS_OK); * get a reply before pub/sub messages arrive. */
if (__redisShiftCallback(&ac->replies,&cb) != REDIS_OK) {
/* No more regular callbacks, the context *must* be subscribed. */
assert(c->flags & REDIS_SUBSCRIBED);
/* TODO: find the right callback for pub/sub message. */
}
if (cb.fn != NULL) { if (cb.fn != NULL) {
c->flags |= REDIS_IN_CALLBACK; c->flags |= REDIS_IN_CALLBACK;
cb.fn(ac,reply,cb.privdata); cb.fn(ac,reply,cb.privdata);
c->flags &= ~REDIS_IN_CALLBACK; c->flags &= ~REDIS_IN_CALLBACK;
c->fn->freeObject(reply);
/* Proceed with free'ing when redisAsyncFree() was called. */ /* Proceed with free'ing when redisAsyncFree() was called. */
if (c->flags & REDIS_FREEING) { if (c->flags & REDIS_FREEING) {
@ -260,6 +268,10 @@ void redisProcessCallbacks(redisAsyncContext *ac) {
return; return;
} }
} else { } else {
/* No callback for this reply. This can either be a NULL callback,
* or there were no callbacks to begin with. Either way, don't
* abort with an error, but simply ignore it because the client
* doesn't know what the server will spit out over the wire. */
c->fn->freeObject(reply); c->fn->freeObject(reply);
} }
} }

View File

@ -71,6 +71,9 @@
/* Flag that is set when an async callback is executed. */ /* Flag that is set when an async callback is executed. */
#define REDIS_IN_CALLBACK 0x10 #define REDIS_IN_CALLBACK 0x10
/* Flag that is set when the async context has one or more subscriptions. */
#define REDIS_SUBSCRIBED 0x20
#define REDIS_REPLY_STRING 1 #define REDIS_REPLY_STRING 1
#define REDIS_REPLY_ARRAY 2 #define REDIS_REPLY_ARRAY 2
#define REDIS_REPLY_INTEGER 3 #define REDIS_REPLY_INTEGER 3