Now the PUSH side of RPOPLPUSH is able to unblock clients blocked on BLPOP
authorantirez <antirez@gmail.com>
Sat, 2 Jan 2010 15:02:24 +0000 (10:02 -0500)
committerantirez <antirez@gmail.com>
Sat, 2 Jan 2010 15:02:24 +0000 (10:02 -0500)
redis.c

diff --git a/redis.c b/redis.c
index ebeccfbe33914fc8a0755bc3b2107151ea81e0e7..a753868777d3ca317593ddfd6a3ea881c2168f69 100644 (file)
--- a/redis.c
+++ b/redis.c
@@ -3862,20 +3862,24 @@ static void rpoplpushcommand(redisClient *c) {
                 robj *ele = listNodeValue(ln);
                 list *dstlist;
 
-                if (dobj == NULL) {
-
-                    /* Create the list if the key does not exist */
-                    dobj = createListObject();
-                    dictAdd(c->db->dict,c->argv[2],dobj);
-                    incrRefCount(c->argv[2]);
-                } else if (dobj->type != REDIS_LIST) {
+                if (dobj && dobj->type != REDIS_LIST) {
                     addReply(c,shared.wrongtypeerr);
                     return;
                 }
-                /* Add the element to the target list */
-                dstlist = dobj->ptr;
-                listAddNodeHead(dstlist,ele);
-                incrRefCount(ele);
+
+                /* Add the element to the target list (unless it's directly
+                 * passed to some BLPOP-ing client */
+                if (!handleClientsWaitingListPush(c,c->argv[2],ele)) {
+                    if (dobj == NULL) {
+                        /* Create the list if the key does not exist */
+                        dobj = createListObject();
+                        dictAdd(c->db->dict,c->argv[2],dobj);
+                        incrRefCount(c->argv[2]);
+                    }
+                    dstlist = dobj->ptr;
+                    listAddNodeHead(dstlist,ele);
+                    incrRefCount(ele);
+                }
 
                 /* Send the element to the client as reply as well */
                 addReplyBulkLen(c,ele);