From d88c3c77beb975c84c23b7586ed6984b4c74b82d Mon Sep 17 00:00:00 2001 From: Pierre Chapuis Date: Sun, 5 Jun 2016 16:22:52 +0200 Subject: [PATCH] make RPUSHX and LPUSHX variadic --- src/server.c | 4 ++-- src/t_list.c | 19 +++++++++++++------ tests/unit/type/list.tcl | 4 +++- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/server.c b/src/server.c index 917fcc77..9ad9f2bc 100644 --- a/src/server.c +++ b/src/server.c @@ -145,8 +145,8 @@ struct redisCommand redisCommandTable[] = { {"mget",mgetCommand,-2,"r",0,NULL,1,-1,1,0,0}, {"rpush",rpushCommand,-3,"wmF",0,NULL,1,1,1,0,0}, {"lpush",lpushCommand,-3,"wmF",0,NULL,1,1,1,0,0}, - {"rpushx",rpushxCommand,3,"wmF",0,NULL,1,1,1,0,0}, - {"lpushx",lpushxCommand,3,"wmF",0,NULL,1,1,1,0,0}, + {"rpushx",rpushxCommand,-3,"wmF",0,NULL,1,1,1,0,0}, + {"lpushx",lpushxCommand,-3,"wmF",0,NULL,1,1,1,0,0}, {"linsert",linsertCommand,5,"wm",0,NULL,1,1,1,0,0}, {"rpop",rpopCommand,2,"wF",0,NULL,1,1,1,0,0}, {"lpop",lpopCommand,2,"wF",0,NULL,1,1,1,0,0}, diff --git a/src/t_list.c b/src/t_list.c index 3777395e..109aba9d 100644 --- a/src/t_list.c +++ b/src/t_list.c @@ -233,19 +233,26 @@ void rpushCommand(client *c) { } void pushxGenericCommand(client *c, int where) { + int j, pushed = 0; robj *subject; if ((subject = lookupKeyWriteOrReply(c,c->argv[1],shared.czero)) == NULL || checkType(c,subject,OBJ_LIST)) return; - char *event = (where == LIST_HEAD) ? "lpush" : "rpush"; - c->argv[2] = tryObjectEncoding(c->argv[2]); - listTypePush(subject,c->argv[2],where); - signalModifiedKey(c->db,c->argv[1]); - notifyKeyspaceEvent(NOTIFY_LIST,event,c->argv[1],c->db->id); - server.dirty++; + for (j = 2; j < c->argc; j++) { + c->argv[j] = tryObjectEncoding(c->argv[j]); + listTypePush(subject,c->argv[j],where); + pushed++; + } addReplyLongLong(c,listTypeLength(subject)); + + if (pushed) { + char *event = (where == LIST_HEAD) ? "lpush" : "rpush"; + signalModifiedKey(c->db,c->argv[1]); + notifyKeyspaceEvent(NOTIFY_LIST,event,c->argv[1],c->db->id); + } + server.dirty += pushed; } void lpushxCommand(client *c) { diff --git a/tests/unit/type/list.tcl b/tests/unit/type/list.tcl index e4d568cf..1557082a 100644 --- a/tests/unit/type/list.tcl +++ b/tests/unit/type/list.tcl @@ -507,7 +507,9 @@ start_server { create_list xlist "$large c" assert_equal 3 [r rpushx xlist d] assert_equal 4 [r lpushx xlist a] - assert_equal "a $large c d" [r lrange xlist 0 -1] + assert_equal 6 [r rpushx xlist 42 x] + assert_equal 9 [r lpushx xlist y3 y2 y1] + assert_equal "y1 y2 y3 a $large c d 42 x" [r lrange xlist 0 -1] } test "LINSERT - $type" {