mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-23 08:38:27 -05:00
update RPOPLPUSH to support dual encoding
This commit is contained in:
parent
be02a7c0d6
commit
0f62e1775d
44
redis.c
44
redis.c
@ -4805,8 +4805,9 @@ static robj *lPop(robj *subject, int where) {
|
|||||||
} else {
|
} else {
|
||||||
value = createStringObjectFromLongLong(vval);
|
value = createStringObjectFromLongLong(vval);
|
||||||
}
|
}
|
||||||
|
/* We only need to delete an element when it exists */
|
||||||
|
subject->ptr = ziplistDelete(subject->ptr,&p);
|
||||||
}
|
}
|
||||||
subject->ptr = ziplistDelete(subject->ptr,&p);
|
|
||||||
} else if (subject->encoding == REDIS_ENCODING_LIST) {
|
} else if (subject->encoding == REDIS_ENCODING_LIST) {
|
||||||
list *list = subject->ptr;
|
list *list = subject->ptr;
|
||||||
listNode *ln;
|
listNode *ln;
|
||||||
@ -5246,47 +5247,38 @@ static void lremCommand(redisClient *c) {
|
|||||||
* as well. This command was originally proposed by Ezra Zygmuntowicz.
|
* as well. This command was originally proposed by Ezra Zygmuntowicz.
|
||||||
*/
|
*/
|
||||||
static void rpoplpushcommand(redisClient *c) {
|
static void rpoplpushcommand(redisClient *c) {
|
||||||
robj *sobj;
|
robj *sobj, *value;
|
||||||
list *srclist;
|
|
||||||
listNode *ln;
|
|
||||||
|
|
||||||
if ((sobj = lookupKeyWriteOrReply(c,c->argv[1],shared.nullbulk)) == NULL ||
|
if ((sobj = lookupKeyWriteOrReply(c,c->argv[1],shared.nullbulk)) == NULL ||
|
||||||
checkType(c,sobj,REDIS_LIST)) return;
|
checkType(c,sobj,REDIS_LIST)) return;
|
||||||
srclist = sobj->ptr;
|
|
||||||
ln = listLast(srclist);
|
|
||||||
|
|
||||||
if (ln == NULL) {
|
if (lLength(sobj) == 0) {
|
||||||
addReply(c,shared.nullbulk);
|
addReply(c,shared.nullbulk);
|
||||||
} else {
|
} else {
|
||||||
robj *dobj = lookupKeyWrite(c->db,c->argv[2]);
|
robj *dobj = lookupKeyWrite(c->db,c->argv[2]);
|
||||||
robj *ele = listNodeValue(ln);
|
if (dobj && checkType(c,dobj,REDIS_LIST)) return;
|
||||||
list *dstlist;
|
value = lPop(sobj,REDIS_TAIL);
|
||||||
|
|
||||||
if (dobj && dobj->type != REDIS_LIST) {
|
|
||||||
addReply(c,shared.wrongtypeerr);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Add the element to the target list (unless it's directly
|
/* Add the element to the target list (unless it's directly
|
||||||
* passed to some BLPOP-ing client */
|
* passed to some BLPOP-ing client */
|
||||||
if (!handleClientsWaitingListPush(c,c->argv[2],ele)) {
|
if (!handleClientsWaitingListPush(c,c->argv[2],value)) {
|
||||||
if (dobj == NULL) {
|
/* Create the list if the key does not exist */
|
||||||
/* Create the list if the key does not exist */
|
if (!dobj) {
|
||||||
dobj = createListObject();
|
dobj = createObject(REDIS_LIST,ziplistNew());
|
||||||
|
dobj->encoding = REDIS_ENCODING_ZIPLIST;
|
||||||
dictAdd(c->db->dict,c->argv[2],dobj);
|
dictAdd(c->db->dict,c->argv[2],dobj);
|
||||||
incrRefCount(c->argv[2]);
|
incrRefCount(c->argv[2]);
|
||||||
}
|
}
|
||||||
dstlist = dobj->ptr;
|
lPush(dobj,value,REDIS_HEAD);
|
||||||
listAddNodeHead(dstlist,ele);
|
|
||||||
incrRefCount(ele);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Send the element to the client as reply as well */
|
/* Send the element to the client as reply as well */
|
||||||
addReplyBulk(c,ele);
|
addReplyBulk(c,value);
|
||||||
|
|
||||||
/* Finally remove the element from the source list */
|
/* lPop returns an object with its refcount incremented */
|
||||||
listDelNode(srclist,ln);
|
decrRefCount(value);
|
||||||
if (listLength(srclist) == 0) deleteKey(c->db,c->argv[1]);
|
|
||||||
|
/* Delete the source list when it is empty */
|
||||||
|
if (lLength(sobj) == 0) deleteKey(c->db,c->argv[1]);
|
||||||
server.dirty++;
|
server.dirty++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user