LPOS: option FIRST renamed RANK.

(cherry picked from commit a5a3a7bbc6)
This commit is contained in:
antirez 2020-06-24 09:07:17 +02:00 committed by Oran Agra
parent 3f5cf24da9
commit 17aaf5ec97
2 changed files with 19 additions and 19 deletions

View File

@ -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;
}

View File

@ -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} {