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
e0022d8c
Commit
e0022d8c
authored
Jun 11, 2020
by
antirez
Browse files
LPOS: tests + crash fix.
parent
495327c0
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/t_list.c
View file @
e0022d8c
...
...
@@ -554,7 +554,7 @@ void lposCommand(client *c) {
/* We return NULL or an empty array if there is no such key (or
* if we find no matches, depending on the presence of the COUNT option. */
if
((
o
=
lookupKey
WriteOrReply
(
c
,
c
->
argv
[
1
]
,
NULL
))
==
NULL
)
{
if
((
o
=
lookupKey
Read
(
c
->
db
,
c
->
argv
[
1
]))
==
NULL
)
{
if
(
count
!=
-
1
)
addReply
(
c
,
shared
.
emptyarray
);
else
...
...
tests/unit/type/list.tcl
View file @
e0022d8c
...
...
@@ -6,6 +6,50 @@ start_server {
}
{
source
"tests/unit/type/list-common.tcl"
test
{
LPOS basic usage
}
{
r DEL mylist
r RPUSH mylist a b c 1 2 3 c c
assert
{[
r LPOS mylist a
]
== 0
}
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 COUNT option
}
{
assert
{[
r LPOS mylist c COUNT 0
]
==
{
2 6 7
}}
assert
{[
r LPOS mylist c COUNT 1
]
==
{
2
}}
assert
{[
r LPOS mylist c COUNT 2
]
==
{
2 6
}}
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 non existing key
}
{
assert
{[
r LPOS mylistxxx c COUNT 0 FIRST 2
]
eq
{}}
}
test
{
LPOS no match
}
{
assert
{[
r LPOS mylist x COUNT 2 FIRST -1
]
eq
{}}
assert
{[
r LPOS mylist x FIRST -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
}}
}
test
{
LPUSH, RPUSH, LLENGTH, LINDEX, LPOP - ziplist
}
{
# first lpush then rpush
assert_equal 1
[
r lpush myziplist1 aa
]
...
...
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