mirror of
https://github.com/fluencelabs/redis
synced 2025-03-19 09:00:51 +00:00
Streams: more advanced XADD and XRANGE tests.
This commit is contained in:
parent
7a41b402c1
commit
fa707ca154
@ -10,6 +10,15 @@ proc streamCompareID {a b} {
|
||||
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 {
|
||||
tags {"stream"}
|
||||
} {
|
||||
@ -39,4 +48,38 @@ start_server {
|
||||
assert {[streamCompareID $id1 $id2] == -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}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user