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
fa707ca1
Commit
fa707ca1
authored
Sep 15, 2017
by
antirez
Browse files
Streams: more advanced XADD and XRANGE tests.
parent
7a41b402
Changes
1
Show whitespace changes
Inline
Side-by-side
tests/unit/type/stream.tcl
View file @
fa707ca1
...
@@ -10,6 +10,15 @@ proc streamCompareID {a b} {
...
@@ -10,6 +10,15 @@ proc streamCompareID {a b} {
if
{
$a
_seq < $b_seq
}
{
return -1
}
if
{
$a
_seq < $b_seq
}
{
return -1
}
}
}
# return the ID immediately greater than the specified one.
# Note that this function does not care to handle 'seq' overflow
# since it's a 64 bit value.
proc streamNextID
{
id
}
{
lassign
[
split $id .
]
ms seq
incr seq
join
[
list $ms $seq
]
.
}
start_server
{
start_server
{
tags
{
"stream"
}
tags
{
"stream"
}
}
{
}
{
...
@@ -39,4 +48,38 @@ start_server {
...
@@ -39,4 +48,38 @@ start_server {
assert
{[
streamCompareID $id1 $id2
]
== -1
}
assert
{[
streamCompareID $id1 $id2
]
== -1
}
assert
{[
streamCompareID $id2 $id3
]
== -1
}
assert
{[
streamCompareID $id2 $id3
]
== -1
}
}
}
test
{
XADD mass insertion and XLEN
}
{
r DEL mystream
r multi
for
{
set j 0
}
{
$j
< 10000
}
{
incr j
}
{
r XADD mystream * item $j
}
r exec
set items
[
r XRANGE mystream - +
]
for
{
set j 0
}
{
$j
< 10000
}
{
incr j
}
{
assert
{[
lindex $items $j 1
]
eq
[
list item $j
]}
}
assert
{[
r xlen mystream
]
== $j
}
}
test
{
XRANGE COUNT works as expected
}
{
assert
{[
llength
[
r xrange mystream - + COUNT 10
]]
== 10
}
}
test
{
XRANGE can be used to iterate the whole stream
}
{
set last_id
"-"
set j 0
while 1
{
set elements
[
r xrange mystream $last_id + COUNT 100
]
if
{[
llength $elements
]
== 0
}
break
foreach e $elements
{
assert
{[
lindex $e 1
]
eq
[
list item $j
]}
incr j
;
}
set last_id
[
streamNextID
[
lindex $elements end 0
]]
}
assert
{
$j
== 10000
}
}
}
}
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