Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
17aaf5ec
You need to sign in or sign up before continuing.
Commit
17aaf5ec
authored
Jun 24, 2020
by
antirez
Committed by
Oran Agra
Jul 20, 2020
Browse files
LPOS: option FIRST renamed RANK.
(cherry picked from commit
a5a3a7bb
)
parent
3f5cf24d
Changes
2
Show whitespace changes
Inline
Side-by-side
src/t_list.c
View file @
17aaf5ec
...
...
@@ -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
;
}
...
...
tests/unit/type/list.tcl
View file @
17aaf5ec
...
...
@@ -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
}
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment