From 17aaf5ec979e0db5c09a0dd4cce0daf48f93ec2d Mon Sep 17 00:00:00 2001 From: antirez Date: Wed, 24 Jun 2020 09:07:17 +0200 Subject: [PATCH] LPOS: option FIRST renamed RANK. (cherry picked from commit a5a3a7bbc61203398ecc1d5b52c76214f5672776) --- src/t_list.c | 10 +++++----- tests/unit/type/list.tcl | 28 ++++++++++++++-------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/t_list.c b/src/t_list.c index e580139ab..2c339888d 100644 --- a/src/t_list.c +++ b/src/t_list.c @@ -487,16 +487,16 @@ void ltrimCommand(client *c) { addReply(c,shared.ok); } -/* LPOS key element [FIRST rank] [COUNT num-matches] [MAXLEN len] +/* LPOS key element [RANK rank] [COUNT num-matches] [MAXLEN len] * - * FIRST "rank" is the position of the match, so if it is 1, the first match + * The "rank" is the position of the match, so if it is 1, the first match * is returned, if it is 2 the second match is returned and so forth. * It is 1 by default. If negative has the same meaning but the search is * performed starting from the end of the list. * * If COUNT is given, instead of returning the single element, a list of * all the matching elements up to "num-matches" are returned. COUNT can - * be combiled with FIRST in order to returning only the element starting + * be combiled with RANK in order to returning only the element starting * from the Nth. If COUNT is zero, all the matching elements are returned. * * MAXLEN tells the command to scan a max of len elements. If zero (the @@ -515,12 +515,12 @@ void lposCommand(client *c) { char *opt = c->argv[j]->ptr; int moreargs = (c->argc-1)-j; - if (!strcasecmp(opt,"FIRST") && moreargs) { + if (!strcasecmp(opt,"RANK") && moreargs) { j++; if (getLongFromObjectOrReply(c, c->argv[j], &rank, NULL) != C_OK) return; if (rank == 0) { - addReplyError(c,"FIRST can't be zero: use 1 to start from " + addReplyError(c,"RANK can't be zero: use 1 to start from " "the first match, 2 from the second, ..."); return; } diff --git a/tests/unit/type/list.tcl b/tests/unit/type/list.tcl index a0c04dcaa..0e39d7d95 100644 --- a/tests/unit/type/list.tcl +++ b/tests/unit/type/list.tcl @@ -13,12 +13,12 @@ start_server { assert {[r LPOS mylist c] == 2} } - test {LPOS FIRST (positive and negative rank) option} { - assert {[r LPOS mylist c FIRST 1] == 2} - assert {[r LPOS mylist c FIRST 2] == 6} - assert {[r LPOS mylist c FIRST 4] eq ""} - assert {[r LPOS mylist c FIRST -1] == 7} - assert {[r LPOS mylist c FIRST -2] == 6} + test {LPOS RANK (positive and negative rank) option} { + assert {[r LPOS mylist c RANK 1] == 2} + assert {[r LPOS mylist c RANK 2] == 6} + assert {[r LPOS mylist c RANK 4] eq ""} + assert {[r LPOS mylist c RANK -1] == 7} + assert {[r LPOS mylist c RANK -2] == 6} } test {LPOS COUNT option} { @@ -28,26 +28,26 @@ start_server { assert {[r LPOS mylist c COUNT 100] == {2 6 7}} } - test {LPOS COUNT + FIRST option} { - assert {[r LPOS mylist c COUNT 0 FIRST 2] == {6 7}} - assert {[r LPOS mylist c COUNT 2 FIRST -1] == {7 6}} + test {LPOS COUNT + RANK option} { + assert {[r LPOS mylist c COUNT 0 RANK 2] == {6 7}} + assert {[r LPOS mylist c COUNT 2 RANK -1] == {7 6}} } test {LPOS non existing key} { - assert {[r LPOS mylistxxx c COUNT 0 FIRST 2] eq {}} + assert {[r LPOS mylistxxx c COUNT 0 RANK 2] eq {}} } test {LPOS no match} { - assert {[r LPOS mylist x COUNT 2 FIRST -1] eq {}} - assert {[r LPOS mylist x FIRST -1] eq {}} + assert {[r LPOS mylist x COUNT 2 RANK -1] eq {}} + assert {[r LPOS mylist x RANK -1] eq {}} } test {LPOS MAXLEN} { assert {[r LPOS mylist a COUNT 0 MAXLEN 1] == {0}} assert {[r LPOS mylist c COUNT 0 MAXLEN 1] == {}} assert {[r LPOS mylist c COUNT 0 MAXLEN 3] == {2}} - assert {[r LPOS mylist c COUNT 0 MAXLEN 3 FIRST -1] == {7 6}} - assert {[r LPOS mylist c COUNT 0 MAXLEN 7 FIRST 2] == {6}} + assert {[r LPOS mylist c COUNT 0 MAXLEN 3 RANK -1] == {7 6}} + assert {[r LPOS mylist c COUNT 0 MAXLEN 7 RANK 2] == {6}} } test {LPUSH, RPUSH, LLENGTH, LINDEX, LPOP - ziplist} {