LPOS: tests + crash fix.
This commit is contained in:
parent
89ca2afd6b
commit
0091125cae
@ -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]
|
||||
|
Loading…
x
Reference in New Issue
Block a user