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
05ba119f
Commit
05ba119f
authored
Jan 08, 2015
by
Salvatore Sanfilippo
Browse files
Merge pull request #2143 from mattsta/quicklist
Quicklist (linked list + ziplist)
parents
9e718a1f
5870e224
Changes
47
Hide whitespace changes
Inline
Side-by-side
tests/support/test.tcl
View file @
05ba119f
...
...
@@ -19,9 +19,12 @@ proc assert_match {pattern value} {
}
}
proc assert_equal
{
expected value
}
{
proc assert_equal
{
expected value
{
detail
""
}
}
{
if
{
$expected
ne $value
}
{
error
"assertion:Expected '
$value
' to be equal to '
$expected
'"
if
{
$detail
ne
""
}
{
set detail
" (detail:
$detail
)"
}
error
"assertion:Expected '
$value
' to be equal to '
$expected
'
$detail
"
}
}
...
...
tests/unit/aofrw.tcl
View file @
05ba119f
...
...
@@ -77,10 +77,10 @@ start_server {tags {"aofrw"}} {
}
foreach d
{
string int
}
{
foreach e
{
ziplist linked
list
}
{
foreach e
{
quick
list
}
{
test
"AOF rewrite of list with
$e
encoding,
$d
data"
{
r flushall
if
{
$e
eq
{
ziplist
}}
{
set len 10
}
else
{
set len 1000
}
set len 1000
for
{
set j 0
}
{
$j
< $len
}
{
incr j
}
{
if
{
$d
eq
{
string
}}
{
set data
[
randstring 0 16 alpha
]
...
...
tests/unit/dump.tcl
View file @
05ba119f
...
...
@@ -157,7 +157,7 @@ start_server {tags {"dump"}} {
test
{
MIGRATE can correctly transfer large values
}
{
set first
[
srv 0 client
]
r del key
for
{
set j 0
}
{
$j
<
5
000
}
{
incr j
}
{
for
{
set j 0
}
{
$j
<
40
000
}
{
incr j
}
{
r rpush key 1 2 3 4 5 6 7 8 9 10
r rpush key
"item 1"
"item 2"
"item 3"
"item 4"
"item 5"
\
"item 6"
"item 7"
"item 8"
"item 9"
"item 10"
...
...
@@ -175,7 +175,7 @@ start_server {tags {"dump"}} {
assert
{[
$first
exists key
]
== 0
}
assert
{[
$second
exists key
]
== 1
}
assert
{[
$second
ttl key
]
== -1
}
assert
{[
$second
llen key
]
==
5
000*20
}
assert
{[
$second
llen key
]
==
40
000*20
}
}
}
...
...
tests/unit/sort.tcl
View file @
05ba119f
start_server
{
tags
{
"sort"
}
overrides
{
"list-max-ziplist-value"
16
"list-max-ziplist-entries"
32
"list-max-ziplist-size"
32
"set-max-intset-entries"
32
}
}
{
...
...
@@ -36,9 +35,9 @@ start_server {
}
foreach
{
num cmd enc title
}
{
16 lpush
zip
list
"Ziplist"
1000 lpush
linked
list
"Linked list"
10000 lpush
linked
list
"Big Linked list"
16 lpush
quick
list
"
Old
Ziplist"
1000 lpush
quick
list
"
Old
Linked list"
10000 lpush
quick
list
"
Old
Big Linked list"
16 sadd intset
"Intset"
1000 sadd hashtable
"Hash table"
10000 sadd hashtable
"Big Hash table"
...
...
@@ -85,14 +84,14 @@ start_server {
r sort tosort BY weight_* store sort-res
assert_equal $result
[
r lrange sort-res 0 -1
]
assert_equal 16
[
r llen sort-res
]
assert_encoding
zip
list sort-res
assert_encoding
quick
list sort-res
}
test
"SORT BY hash field STORE"
{
r sort tosort BY wobj_*->weight store sort-res
assert_equal $result
[
r lrange sort-res 0 -1
]
assert_equal 16
[
r llen sort-res
]
assert_encoding
zip
list sort-res
assert_encoding
quick
list sort-res
}
test
"SORT extracts STORE correctly"
{
...
...
tests/unit/type/list-2.tcl
View file @
05ba119f
start_server
{
tags
{
"list"
}
overrides
{
"list-max-ziplist-value"
16
"list-max-ziplist-entries"
256
"list-max-ziplist-size"
4
}
}
{
source
"tests/unit/type/list-common.tcl"
...
...
@@ -28,14 +27,18 @@ start_server {
for
{
set i 0
}
{
$i
< 1000
}
{
incr i
}
{
set min
[
expr
{
int
(
rand
()
*$startlen
)}]
set max
[
expr
{
$min
+int
(
rand
()
*$startlen
)}]
set before_len
[
llength $mylist
]
set before_len_r
[
r llen mylist
]
set mylist
[
lrange $mylist $min $max
]
r ltrim mylist $min $max
assert_equal $mylist
[
r lrange mylist 0 -1
]
assert_equal $mylist
[
r lrange mylist 0 -1
]
"failed trim"
set starting
[
r llen mylist
]
for
{
set j
[
r llen mylist
]}
{
$j
< $startlen
}
{
incr j
}
{
set str
[
randomInt 9223372036854775807
]
r rpush mylist $str
lappend mylist $str
assert_equal $mylist
[
r lrange mylist 0 -1
]
"failed append match"
}
}
}
...
...
tests/unit/type/list-3.tcl
View file @
05ba119f
start_server
{
tags
{
list ziplist
}
overrides
{
"list-max-ziplist-value"
200000
"list-max-ziplist-entries"
256
"list-max-ziplist-size"
16
}
}
{
test
{
Explicit regression for a list bug
}
{
...
...
tests/unit/type/list.tcl
View file @
05ba119f
start_server
{
tags
{
"list"
}
overrides
{
"list-max-ziplist-value"
16
"list-max-ziplist-entries"
256
"list-max-ziplist-size"
5
}
}
{
source
"tests/unit/type/list-common.tcl"
test
{
LPUSH, RPUSH, LLENGTH, LINDEX, LPOP - ziplist
}
{
# first lpush then rpush
assert_equal 1
[
r lpush myziplist1 a
]
assert_equal 2
[
r rpush myziplist1 b
]
assert_equal 3
[
r rpush myziplist1 c
]
assert_equal 1
[
r lpush myziplist1
a
a
]
assert_equal 2
[
r rpush myziplist1
b
b
]
assert_equal 3
[
r rpush myziplist1
c
c
]
assert_equal 3
[
r llen myziplist1
]
assert_equal a
[
r lindex myziplist1 0
]
assert_equal b
[
r lindex myziplist1 1
]
assert_equal c
[
r lindex myziplist1 2
]
assert_equal a
a
[
r lindex myziplist1 0
]
assert_equal b
b
[
r lindex myziplist1 1
]
assert_equal c
c
[
r lindex myziplist1 2
]
assert_equal
{}
[
r lindex myziplist2 3
]
assert_equal c
[
r rpop myziplist1
]
assert_equal a
[
r lpop myziplist1
]
assert_encoding
zip
list myziplist1
assert_equal c
c
[
r rpop myziplist1
]
assert_equal a
a
[
r lpop myziplist1
]
assert_encoding
quick
list myziplist1
# first rpush then lpush
assert_equal 1
[
r rpush myziplist2 a
]
...
...
@@ -32,13 +31,13 @@ start_server {
assert_equal
{}
[
r lindex myziplist2 3
]
assert_equal a
[
r rpop myziplist2
]
assert_equal c
[
r lpop myziplist2
]
assert_encoding
zip
list myziplist2
assert_encoding
quick
list myziplist2
}
test
{
LPUSH, RPUSH, LLENGTH, LINDEX, LPOP - regular list
}
{
# first lpush then rpush
assert_equal 1
[
r lpush mylist1 $largevalue
(
linkedlist
)]
assert_encoding
linked
list mylist1
assert_encoding
quick
list mylist1
assert_equal 2
[
r rpush mylist1 b
]
assert_equal 3
[
r rpush mylist1 c
]
assert_equal 3
[
r llen mylist1
]
...
...
@@ -51,7 +50,7 @@ start_server {
# first rpush then lpush
assert_equal 1
[
r rpush mylist2 $largevalue
(
linkedlist
)]
assert_encoding
linked
list mylist2
assert_encoding
quick
list mylist2
assert_equal 2
[
r lpush mylist2 b
]
assert_equal 3
[
r lpush mylist2 c
]
assert_equal 3
[
r llen mylist2
]
...
...
@@ -74,34 +73,22 @@ start_server {
assert_equal
{
d c b a 0 1 2 3
}
[
r lrange mylist 0 -1
]
}
test
{
DEL a list - ziplist
}
{
assert_equal 1
[
r del myziplist2
]
assert_equal 0
[
r exists myziplist2
]
assert_equal 0
[
r llen myziplist2
]
}
test
{
DEL a list - regular list
}
{
test
{
DEL a list
}
{
assert_equal 1
[
r del mylist2
]
assert_equal 0
[
r exists mylist2
]
assert_equal 0
[
r llen mylist2
]
}
proc create_ziplist
{
key entries
}
{
r del $key
foreach entry $entries
{
r rpush $key $entry
}
assert_encoding ziplist $key
}
proc create_linkedlist
{
key entries
}
{
proc create_list
{
key entries
}
{
r del $key
foreach entry $entries
{
r rpush $key $entry
}
assert_encoding
linked
list $key
assert_encoding
quick
list $key
}
foreach
{
type large
}
[
array get largevalue
]
{
test
"BLPOP, BRPOP: single existing list -
$type
"
{
set rd
[
redis_deferring_client
]
create_
$type
blist
"a b
$large
c d"
create_
list
blist
"a b
$large
c d"
$rd blpop blist 1
assert_equal
{
blist a
}
[
$rd
read
]
...
...
@@ -116,8 +103,8 @@ start_server {
test
"BLPOP, BRPOP: multiple existing lists -
$type
"
{
set rd
[
redis_deferring_client
]
create_
$type
blist1
"a
$large
c"
create_
$type
blist2
"d
$large
f"
create_
list
blist1
"a
$large
c"
create_
list
blist2
"d
$large
f"
$rd blpop blist1 blist2 1
assert_equal
{
blist1 a
}
[
$rd
read
]
...
...
@@ -137,7 +124,7 @@ start_server {
test
"BLPOP, BRPOP: second list has an entry -
$type
"
{
set rd
[
redis_deferring_client
]
r del blist1
create_
$type
blist2
"d
$large
f"
create_
list
blist2
"d
$large
f"
$rd blpop blist1 blist2 1
assert_equal
{
blist2 d
}
[
$rd
read
]
...
...
@@ -151,7 +138,7 @@ start_server {
r del target
set rd
[
redis_deferring_client
]
create_
$type
blist
"a b
$large
c d"
create_
list
blist
"a b
$large
c d"
$rd brpoplpush blist target 1
assert_equal d
[
$rd
read
]
...
...
@@ -517,28 +504,28 @@ start_server {
foreach
{
type large
}
[
array get largevalue
]
{
test
"LPUSHX, RPUSHX -
$type
"
{
create_
$type
xlist
"
$large
c"
create_
list
xlist
"
$large
c"
assert_equal 3
[
r rpushx xlist d
]
assert_equal 4
[
r lpushx xlist a
]
assert_equal
"a
$large
c d"
[
r lrange xlist 0 -1
]
}
test
"LINSERT -
$type
"
{
create_
$type
xlist
"a
$large
c d"
assert_equal 5
[
r linsert xlist before c zz
]
assert_equal
"a
$large
zz c d"
[
r lrange xlist 0 10
]
assert_equal 6
[
r linsert xlist after c yy
]
assert_equal
"a
$large
zz c yy d"
[
r lrange xlist 0 10
]
assert_equal 7
[
r linsert xlist after d dd
]
assert_equal -1
[
r linsert xlist after bad ddd
]
assert_equal
"a
$large
zz c yy d dd"
[
r lrange xlist 0 10
]
assert_equal 8
[
r linsert xlist before a aa
]
assert_equal -1
[
r linsert xlist before bad aaa
]
assert_equal
"aa a
$large
zz c yy d dd"
[
r lrange xlist 0 10
]
create_
list
xlist
"a
$large
c d"
assert_equal 5
[
r linsert xlist before c zz
]
"before c"
assert_equal
"a
$large
zz c d"
[
r lrange xlist 0 10
]
"lrangeA"
assert_equal 6
[
r linsert xlist after c yy
]
"after c"
assert_equal
"a
$large
zz c yy d"
[
r lrange xlist 0 10
]
"lrangeB"
assert_equal 7
[
r linsert xlist after d dd
]
"after d"
assert_equal -1
[
r linsert xlist after bad ddd
]
"after bad"
assert_equal
"a
$large
zz c yy d dd"
[
r lrange xlist 0 10
]
"lrangeC"
assert_equal 8
[
r linsert xlist before a aa
]
"before a"
assert_equal -1
[
r linsert xlist before bad aaa
]
"before bad"
assert_equal
"aa a
$large
zz c yy d dd"
[
r lrange xlist 0 10
]
"lrangeD"
# check inserting integer encoded value
assert_equal 9
[
r linsert xlist before aa 42
]
assert_equal 42
[
r lrange xlist 0 0
]
assert_equal 9
[
r linsert xlist before aa 42
]
"before aa"
assert_equal 42
[
r lrange xlist 0 0
]
"lrangeE"
}
}
...
...
@@ -547,55 +534,7 @@ start_server {
set e
}
{
*ERR*syntax*error*
}
test
{
LPUSHX, RPUSHX convert from ziplist to list
}
{
set large $largevalue
(
linkedlist
)
# convert when a large value is pushed
create_ziplist xlist a
assert_equal 2
[
r rpushx xlist $large
]
assert_encoding linkedlist xlist
create_ziplist xlist a
assert_equal 2
[
r lpushx xlist $large
]
assert_encoding linkedlist xlist
# convert when the length threshold is exceeded
create_ziplist xlist
[
lrepeat 256 a
]
assert_equal 257
[
r rpushx xlist b
]
assert_encoding linkedlist xlist
create_ziplist xlist
[
lrepeat 256 a
]
assert_equal 257
[
r lpushx xlist b
]
assert_encoding linkedlist xlist
}
test
{
LINSERT convert from ziplist to list
}
{
set large $largevalue
(
linkedlist
)
# convert when a large value is inserted
create_ziplist xlist a
assert_equal 2
[
r linsert xlist before a $large
]
assert_encoding linkedlist xlist
create_ziplist xlist a
assert_equal 2
[
r linsert xlist after a $large
]
assert_encoding linkedlist xlist
# convert when the length threshold is exceeded
create_ziplist xlist
[
lrepeat 256 a
]
assert_equal 257
[
r linsert xlist before a a
]
assert_encoding linkedlist xlist
create_ziplist xlist
[
lrepeat 256 a
]
assert_equal 257
[
r linsert xlist after a a
]
assert_encoding linkedlist xlist
# don't convert when the value could not be inserted
create_ziplist xlist
[
lrepeat 256 a
]
assert_equal -1
[
r linsert xlist before foo a
]
assert_encoding ziplist xlist
create_ziplist xlist
[
lrepeat 256 a
]
assert_equal -1
[
r linsert xlist after foo a
]
assert_encoding ziplist xlist
}
foreach
{
type num
}
{
ziplist 250 linkedlist 500
}
{
foreach
{
type num
}
{
quicklist 250 quicklist 500
}
{
proc check_numbered_list_consistency
{
key
}
{
set len
[
r llen $key
]
for
{
set i 0
}
{
$i
< $len
}
{
incr i
}
{
...
...
@@ -664,16 +603,16 @@ start_server {
foreach
{
type large
}
[
array get largevalue
]
{
test
"RPOPLPUSH base case -
$type
"
{
r del mylist1 mylist2
create_
$type
mylist1
"a
$large
c d"
create_
list
mylist1
"a
$large
c d"
assert_equal d
[
r rpoplpush mylist1 mylist2
]
assert_equal c
[
r rpoplpush mylist1 mylist2
]
assert_equal
"a
$large
"
[
r lrange mylist1 0 -1
]
assert_equal
"c d"
[
r lrange mylist2 0 -1
]
assert_encoding
zip
list mylist2
assert_encoding
quick
list mylist2
}
test
"RPOPLPUSH with the same list as src and dst -
$type
"
{
create_
$type
mylist
"a
$large
c"
create_
list
mylist
"a
$large
c"
assert_equal
"a
$large
c"
[
r lrange mylist 0 -1
]
assert_equal c
[
r rpoplpush mylist mylist
]
assert_equal
"c a
$large
"
[
r lrange mylist 0 -1
]
...
...
@@ -681,8 +620,8 @@ start_server {
foreach
{
othertype otherlarge
}
[
array get largevalue
]
{
test
"RPOPLPUSH with
$type
source and existing target
$othertype
"
{
create_
$type
srclist
"a b c
$large
"
create_
$othertype
dstlist
"
$otherlarge
"
create_
list
srclist
"a b c
$large
"
create_
list
dstlist
"
$otherlarge
"
assert_equal $large
[
r rpoplpush srclist dstlist
]
assert_equal c
[
r rpoplpush srclist dstlist
]
assert_equal
"a b"
[
r lrange srclist 0 -1
]
...
...
@@ -691,7 +630,7 @@ start_server {
# When we rpoplpush'ed a large value, dstlist should be
# converted to the same encoding as srclist.
if
{
$type
eq
"linkedlist"
}
{
assert_encoding
linked
list dstlist
assert_encoding
quick
list dstlist
}
}
}
...
...
@@ -713,7 +652,7 @@ start_server {
}
test
{
RPOPLPUSH against non list dst key
}
{
create_
zip
list srclist
{
a b c d
}
create_list srclist
{
a b c d
}
r set dstlist x
assert_error WRONGTYPE*
{
r rpoplpush srclist dstlist
}
assert_type string dstlist
...
...
@@ -727,7 +666,7 @@ start_server {
foreach
{
type large
}
[
array get largevalue
]
{
test
"Basic LPOP/RPOP -
$type
"
{
create_
$type
mylist
"
$large
1 2"
create_
list
mylist
"
$large
1 2"
assert_equal $large
[
r lpop mylist
]
assert_equal 2
[
r rpop mylist
]
assert_equal 1
[
r lpop mylist
]
...
...
@@ -745,7 +684,7 @@ start_server {
assert_error WRONGTYPE*
{
r rpop notalist
}
}
foreach
{
type num
}
{
zip
list 250
linked
list 500
}
{
foreach
{
type num
}
{
quick
list 250
quick
list 500
}
{
test
"Mass RPOP/LPOP -
$type
"
{
r del mylist
set sum1 0
...
...
@@ -765,24 +704,24 @@ start_server {
foreach
{
type large
}
[
array get largevalue
]
{
test
"LRANGE basics -
$type
"
{
create_
$type
mylist
"
$large
1 2 3 4 5 6 7 8 9"
create_
list
mylist
"
$large
1 2 3 4 5 6 7 8 9"
assert_equal
{
1 2 3 4 5 6 7 8
}
[
r lrange mylist 1 -2
]
assert_equal
{
7 8 9
}
[
r lrange mylist -3 -1
]
assert_equal
{
4
}
[
r lrange mylist 4 4
]
}
test
"LRANGE inverted indexes -
$type
"
{
create_
$type
mylist
"
$large
1 2 3 4 5 6 7 8 9"
create_
list
mylist
"
$large
1 2 3 4 5 6 7 8 9"
assert_equal
{}
[
r lrange mylist 6 2
]
}
test
"LRANGE out of range indexes including the full list -
$type
"
{
create_
$type
mylist
"
$large
1 2 3"
create_
list
mylist
"
$large
1 2 3"
assert_equal
"
$large
1 2 3"
[
r lrange mylist -1000 1000
]
}
test
"LRANGE out of range negative end index -
$type
"
{
create_
$type
mylist
"
$large
1 2 3"
create_
list
mylist
"
$large
1 2 3"
assert_equal $large
[
r lrange mylist 0 -4
]
assert_equal
{}
[
r lrange mylist 0 -5
]
}
...
...
@@ -796,7 +735,7 @@ start_server {
proc trim_list
{
type min max
}
{
upvar 1 large large
r del mylist
create_
$type
mylist
"1 2 3 4
$large
"
create_
list
mylist
"1 2 3 4
$large
"
r ltrim mylist $min $max
r lrange mylist 0 -1
}
...
...
@@ -825,7 +764,7 @@ start_server {
foreach
{
type large
}
[
array get largevalue
]
{
test
"LSET -
$type
"
{
create_
$type
mylist
"99 98
$large
96 95"
create_
list
mylist
"99 98
$large
96 95"
r lset mylist 1 foo
r lset mylist -1 bar
assert_equal
"99 foo
$large
96 bar"
[
r lrange mylist 0 -1
]
...
...
@@ -847,7 +786,7 @@ start_server {
foreach
{
type e
}
[
array get largevalue
]
{
test
"LREM remove all the occurrences -
$type
"
{
create_
$type
mylist
"
$e
foo bar foobar foobared zap bar test foo"
create_
list
mylist
"
$e
foo bar foobar foobared zap bar test foo"
assert_equal 2
[
r lrem mylist 0 bar
]
assert_equal
"
$e
foo foobar foobared zap test foo"
[
r lrange mylist 0 -1
]
}
...
...
@@ -863,7 +802,7 @@ start_server {
}
test
"LREM starting from tail with negative count -
$type
"
{
create_
$type
mylist
"
$e
foo bar foobar foobared zap bar test foo foo"
create_
list
mylist
"
$e
foo bar foobar foobared zap bar test foo foo"
assert_equal 1
[
r lrem mylist -1 bar
]
assert_equal
"
$e
foo bar foobar foobared zap test foo foo"
[
r lrange mylist 0 -1
]
}
...
...
@@ -874,7 +813,7 @@ start_server {
}
test
"LREM deleting objects that may be int encoded -
$type
"
{
create_
$type
myotherlist
"
$e
1 2 3"
create_
list
myotherlist
"
$e
1 2 3"
assert_equal 1
[
r lrem myotherlist 1 2
]
assert_equal 3
[
r llen myotherlist
]
}
...
...
Prev
1
2
3
Next
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