Commit fb2feae5 authored by antirez's avatar antirez
Browse files

variadic LPUSH/RPUSH

parent 7c0e1b53
...@@ -85,8 +85,8 @@ struct redisCommand redisCommandTable[] = { ...@@ -85,8 +85,8 @@ struct redisCommand redisCommandTable[] = {
{"incr",incrCommand,2,REDIS_CMD_DENYOOM,NULL,1,1,1,0,0}, {"incr",incrCommand,2,REDIS_CMD_DENYOOM,NULL,1,1,1,0,0},
{"decr",decrCommand,2,REDIS_CMD_DENYOOM,NULL,1,1,1,0,0}, {"decr",decrCommand,2,REDIS_CMD_DENYOOM,NULL,1,1,1,0,0},
{"mget",mgetCommand,-2,0,NULL,1,-1,1,0,0}, {"mget",mgetCommand,-2,0,NULL,1,-1,1,0,0},
{"rpush",rpushCommand,3,REDIS_CMD_DENYOOM,NULL,1,1,1,0,0}, {"rpush",rpushCommand,-3,REDIS_CMD_DENYOOM,NULL,1,1,1,0,0},
{"lpush",lpushCommand,3,REDIS_CMD_DENYOOM,NULL,1,1,1,0,0}, {"lpush",lpushCommand,-3,REDIS_CMD_DENYOOM,NULL,1,1,1,0,0},
{"rpushx",rpushxCommand,3,REDIS_CMD_DENYOOM,NULL,1,1,1,0,0}, {"rpushx",rpushxCommand,3,REDIS_CMD_DENYOOM,NULL,1,1,1,0,0},
{"lpushx",lpushxCommand,3,REDIS_CMD_DENYOOM,NULL,1,1,1,0,0}, {"lpushx",lpushxCommand,3,REDIS_CMD_DENYOOM,NULL,1,1,1,0,0},
{"linsert",linsertCommand,5,REDIS_CMD_DENYOOM,NULL,1,1,1,0,0}, {"linsert",linsertCommand,5,REDIS_CMD_DENYOOM,NULL,1,1,1,0,0},
......
...@@ -259,30 +259,35 @@ void listTypeConvert(robj *subject, int enc) { ...@@ -259,30 +259,35 @@ void listTypeConvert(robj *subject, int enc) {
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/
void pushGenericCommand(redisClient *c, int where) { void pushGenericCommand(redisClient *c, int where) {
int j, addlen = 0, pushed = 0;
robj *lobj = lookupKeyWrite(c->db,c->argv[1]); robj *lobj = lookupKeyWrite(c->db,c->argv[1]);
c->argv[2] = tryObjectEncoding(c->argv[2]); int may_have_waiting_clients = (lobj == NULL);
if (lobj == NULL) {
if (handleClientsWaitingListPush(c,c->argv[1],c->argv[2])) { if (lobj && lobj->type != REDIS_LIST) {
addReply(c,shared.cone); addReply(c,shared.wrongtypeerr);
return; return;
} }
lobj = createZiplistObject();
dbAdd(c->db,c->argv[1],lobj); for (j = 2; j < c->argc; j++) {
} else { c->argv[j] = tryObjectEncoding(c->argv[j]);
if (lobj->type != REDIS_LIST) { if (may_have_waiting_clients) {
addReply(c,shared.wrongtypeerr); if (handleClientsWaitingListPush(c,c->argv[1],c->argv[j])) {
return; addlen++;
continue;
} else {
may_have_waiting_clients = 0;
}
} }
if (handleClientsWaitingListPush(c,c->argv[1],c->argv[2])) { if (!lobj) {
signalModifiedKey(c->db,c->argv[1]); lobj = createZiplistObject();
addReply(c,shared.cone); dbAdd(c->db,c->argv[1],lobj);
return;
} }
listTypePush(lobj,c->argv[j],where);
pushed++;
} }
listTypePush(lobj,c->argv[2],where); addReplyLongLong(c,addlen + (lobj ? listTypeLength(lobj) : 0));
addReplyLongLong(c,listTypeLength(lobj)); if (pushed) signalModifiedKey(c->db,c->argv[1]);
signalModifiedKey(c->db,c->argv[1]); server.dirty += pushed;
server.dirty++;
} }
void lpushCommand(redisClient *c) { void lpushCommand(redisClient *c) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment