提交 0091125c 编写于 作者: A antirez

LPOS: tests + crash fix.

上级 89ca2afd
......@@ -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 = lookupKeyWriteOrReply(c,c->argv[1],NULL)) == NULL) {
if ((o = lookupKeyRead(c->db,c->argv[1])) == NULL) {
if (count != -1)
addReply(c,shared.emptyarray);
else
......
......@@ -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]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册