mirror of
http://github.com/valkey-io/valkey
synced 2024-11-22 09:17:20 +00:00
LPOS: option FIRST renamed RANK.
(cherry picked from commit a5a3a7bbc6
)
This commit is contained in:
parent
3f5cf24da9
commit
17aaf5ec97
10
src/t_list.c
10
src/t_list.c
@ -487,16 +487,16 @@ void ltrimCommand(client *c) {
|
|||||||
addReply(c,shared.ok);
|
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.
|
* 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
|
* It is 1 by default. If negative has the same meaning but the search is
|
||||||
* performed starting from the end of the list.
|
* performed starting from the end of the list.
|
||||||
*
|
*
|
||||||
* If COUNT is given, instead of returning the single element, a list of
|
* 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
|
* 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.
|
* 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
|
* 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;
|
char *opt = c->argv[j]->ptr;
|
||||||
int moreargs = (c->argc-1)-j;
|
int moreargs = (c->argc-1)-j;
|
||||||
|
|
||||||
if (!strcasecmp(opt,"FIRST") && moreargs) {
|
if (!strcasecmp(opt,"RANK") && moreargs) {
|
||||||
j++;
|
j++;
|
||||||
if (getLongFromObjectOrReply(c, c->argv[j], &rank, NULL) != C_OK)
|
if (getLongFromObjectOrReply(c, c->argv[j], &rank, NULL) != C_OK)
|
||||||
return;
|
return;
|
||||||
if (rank == 0) {
|
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, ...");
|
"the first match, 2 from the second, ...");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -13,12 +13,12 @@ start_server {
|
|||||||
assert {[r LPOS mylist c] == 2}
|
assert {[r LPOS mylist c] == 2}
|
||||||
}
|
}
|
||||||
|
|
||||||
test {LPOS FIRST (positive and negative rank) option} {
|
test {LPOS RANK (positive and negative rank) option} {
|
||||||
assert {[r LPOS mylist c FIRST 1] == 2}
|
assert {[r LPOS mylist c RANK 1] == 2}
|
||||||
assert {[r LPOS mylist c FIRST 2] == 6}
|
assert {[r LPOS mylist c RANK 2] == 6}
|
||||||
assert {[r LPOS mylist c FIRST 4] eq ""}
|
assert {[r LPOS mylist c RANK 4] eq ""}
|
||||||
assert {[r LPOS mylist c FIRST -1] == 7}
|
assert {[r LPOS mylist c RANK -1] == 7}
|
||||||
assert {[r LPOS mylist c FIRST -2] == 6}
|
assert {[r LPOS mylist c RANK -2] == 6}
|
||||||
}
|
}
|
||||||
|
|
||||||
test {LPOS COUNT option} {
|
test {LPOS COUNT option} {
|
||||||
@ -28,26 +28,26 @@ start_server {
|
|||||||
assert {[r LPOS mylist c COUNT 100] == {2 6 7}}
|
assert {[r LPOS mylist c COUNT 100] == {2 6 7}}
|
||||||
}
|
}
|
||||||
|
|
||||||
test {LPOS COUNT + FIRST option} {
|
test {LPOS COUNT + RANK option} {
|
||||||
assert {[r LPOS mylist c COUNT 0 FIRST 2] == {6 7}}
|
assert {[r LPOS mylist c COUNT 0 RANK 2] == {6 7}}
|
||||||
assert {[r LPOS mylist c COUNT 2 FIRST -1] == {7 6}}
|
assert {[r LPOS mylist c COUNT 2 RANK -1] == {7 6}}
|
||||||
}
|
}
|
||||||
|
|
||||||
test {LPOS non existing key} {
|
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} {
|
test {LPOS no match} {
|
||||||
assert {[r LPOS mylist x COUNT 2 FIRST -1] eq {}}
|
assert {[r LPOS mylist x COUNT 2 RANK -1] eq {}}
|
||||||
assert {[r LPOS mylist x FIRST -1] eq {}}
|
assert {[r LPOS mylist x RANK -1] eq {}}
|
||||||
}
|
}
|
||||||
|
|
||||||
test {LPOS MAXLEN} {
|
test {LPOS MAXLEN} {
|
||||||
assert {[r LPOS mylist a COUNT 0 MAXLEN 1] == {0}}
|
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 1] == {}}
|
||||||
assert {[r LPOS mylist c COUNT 0 MAXLEN 3] == {2}}
|
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 3 RANK -1] == {7 6}}
|
||||||
assert {[r LPOS mylist c COUNT 0 MAXLEN 7 FIRST 2] == {6}}
|
assert {[r LPOS mylist c COUNT 0 MAXLEN 7 RANK 2] == {6}}
|
||||||
}
|
}
|
||||||
|
|
||||||
test {LPUSH, RPUSH, LLENGTH, LINDEX, LPOP - ziplist} {
|
test {LPUSH, RPUSH, LLENGTH, LINDEX, LPOP - ziplist} {
|
||||||
|
Loading…
Reference in New Issue
Block a user