- addReplyMultiBulkLen(receiver,2);
- addReplyBulk(receiver,key);
- addReplyBulk(receiver,ele);
+ if (receiver->bpop.target == NULL) {
+ /* BRPOP/BLPOP return a multi-bulk with the name
+ * of the popped list */
+ addReplyMultiBulkLen(receiver,2);
+ addReplyBulk(receiver,key);
+ addReplyBulk(receiver,ele);
+ }
+ else {
+ /* BRPOPLPUSH */
+ robj *dobj = lookupKeyWrite(receiver->db,receiver->bpop.target);
+ if (dobj && checkType(receiver,dobj,REDIS_LIST)) return 0;
+
+ addReplyBulk(receiver,ele);
+
+ if (!handleClientsWaitingListPush(receiver, receiver->bpop.target, ele)) {
+ /* Create the list if the key does not exist */
+ if (!dobj) {
+ dobj = createZiplistObject();
+ dbAdd(receiver->db, receiver->bpop.target, dobj);
+ }
+
+ listTypePush(dobj, ele, REDIS_HEAD);
+ }
+ }
+