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
b34fc03e
Commit
b34fc03e
authored
Jan 12, 2021
by
Oran Agra
Browse files
Merge unstable into 6.2
parents
b8c67ce4
4f8458d8
Changes
86
Hide whitespace changes
Inline
Side-by-side
tests/unit/tracking.tcl
View file @
b34fc03e
...
...
@@ -132,7 +132,24 @@ start_server {tags {"tracking"}} {
test
{
HELLO 3 reply is correct
}
{
set reply
[
r HELLO 3
]
assert
{[
lindex $reply 2
]
eq
{
proto 3
}}
assert_equal
[
dict get $reply proto
]
3
}
test
{
HELLO without protover
}
{
set reply
[
r HELLO 3
]
assert_equal
[
dict get $reply proto
]
3
set reply
[
r HELLO
]
assert_equal
[
dict get $reply proto
]
3
set reply
[
r HELLO 2
]
assert_equal
[
dict get $reply proto
]
2
set reply
[
r HELLO
]
assert_equal
[
dict get $reply proto
]
2
# restore RESP3 for next test
r HELLO 3
}
test
{
RESP3 based basic invalidation
}
{
...
...
@@ -306,7 +323,25 @@ start_server {tags {"tracking"}} {
set ping_reply
[
$rd
read
]
assert
{
$inv
_msg eq
{
invalidate key1
}}
assert
{
$ping
_reply eq
{
PONG
}}
}
}
test
{
BCAST with prefix collisions throw errors
}
{
set r
[
redis_client
]
catch
{
$r
CLIENT TRACKING ON BCAST PREFIX FOOBAR PREFIX FOO
}
output
assert_match
{
ERR Prefix 'FOOBAR'*'FOO'*
}
$output
catch
{
$r
CLIENT TRACKING ON BCAST PREFIX FOO PREFIX FOOBAR
}
output
assert_match
{
ERR Prefix 'FOO'*'FOOBAR'*
}
$output
$r CLIENT TRACKING ON BCAST PREFIX FOO PREFIX BAR
catch
{
$r
CLIENT TRACKING ON BCAST PREFIX FO
}
output
assert_match
{
ERR Prefix 'FO'*'FOO'*
}
$output
catch
{
$r
CLIENT TRACKING ON BCAST PREFIX BARB
}
output
assert_match
{
ERR Prefix 'BARB'*'BAR'*
}
$output
$r CLIENT TRACKING OFF
}
test
{
Tracking gets notification on tracking table key eviction
}
{
$rd_redirection HELLO 2
...
...
@@ -398,6 +433,85 @@ start_server {tags {"tracking"}} {
assert
{
$total
_prefixes == 1
}
}
test
{
CLIENT TRACKINGINFO provides reasonable results when tracking off
}
{
r CLIENT TRACKING off
set res
[
r client trackinginfo
]
set flags
[
dict get $res flags
]
assert_equal
{
off
}
$flags
set redirect
[
dict get $res redirect
]
assert_equal
{
-1
}
$redirect
set prefixes
[
dict get $res prefixes
]
assert_equal
{}
$prefixes
}
test
{
CLIENT TRACKINGINFO provides reasonable results when tracking on
}
{
r CLIENT TRACKING on
set res
[
r client trackinginfo
]
set flags
[
dict get $res flags
]
assert_equal
{
on
}
$flags
set redirect
[
dict get $res redirect
]
assert_equal
{
0
}
$redirect
set prefixes
[
dict get $res prefixes
]
assert_equal
{}
$prefixes
}
test
{
CLIENT TRACKINGINFO provides reasonable results when tracking on with options
}
{
r CLIENT TRACKING on REDIRECT $redir_id noloop
set res
[
r client trackinginfo
]
set flags
[
dict get $res flags
]
assert_equal
{
on noloop
}
$flags
set redirect
[
dict get $res redirect
]
assert_equal $redir_id $redirect
set prefixes
[
dict get $res prefixes
]
assert_equal
{}
$prefixes
}
test
{
CLIENT TRACKINGINFO provides reasonable results when tracking optin
}
{
r CLIENT TRACKING off
r CLIENT TRACKING on optin
set res
[
r client trackinginfo
]
set flags
[
dict get $res flags
]
assert_equal
{
on optin
}
$flags
set redirect
[
dict get $res redirect
]
assert_equal
{
0
}
$redirect
set prefixes
[
dict get $res prefixes
]
assert_equal
{}
$prefixes
r CLIENT CACHING yes
set res
[
r client trackinginfo
]
set flags
[
dict get $res flags
]
assert_equal
{
on optin caching-yes
}
$flags
}
test
{
CLIENT TRACKINGINFO provides reasonable results when tracking optout
}
{
r CLIENT TRACKING off
r CLIENT TRACKING on optout
set res
[
r client trackinginfo
]
set flags
[
dict get $res flags
]
assert_equal
{
on optout
}
$flags
set redirect
[
dict get $res redirect
]
assert_equal
{
0
}
$redirect
set prefixes
[
dict get $res prefixes
]
assert_equal
{}
$prefixes
r CLIENT CACHING no
set res
[
r client trackinginfo
]
set flags
[
dict get $res flags
]
assert_equal
{
on optout caching-no
}
$flags
}
test
{
CLIENT TRACKINGINFO provides reasonable results when tracking bcast mode
}
{
r CLIENT TRACKING off
r CLIENT TRACKING on BCAST PREFIX foo PREFIX bar
set res
[
r client trackinginfo
]
set flags
[
dict get $res flags
]
assert_equal
{
on bcast
}
$flags
set redirect
[
dict get $res redirect
]
assert_equal
{
0
}
$redirect
set prefixes
[
lsort
[
dict get $res prefixes
]]
assert_equal
{
bar foo
}
$prefixes
}
$rd_redirection close
$rd close
}
tests/unit/type/list.tcl
View file @
b34fc03e
...
...
@@ -123,6 +123,17 @@ start_server {
test
{
R/LPOP against empty list
}
{
r lpop non-existing-list
}
{}
test
{
R/LPOP with the optional count argument
}
{
assert_equal 7
[
r lpush listcount aa bb cc dd ee ff gg
]
assert_equal
{}
[
r lpop listcount 0
]
assert_equal
{
gg
}
[
r lpop listcount 1
]
assert_equal
{
ff ee
}
[
r lpop listcount 2
]
assert_equal
{
aa bb
}
[
r rpop listcount 2
]
assert_equal
{
cc
}
[
r rpop listcount 1
]
assert_equal
{
dd
}
[
r rpop listcount 123
]
assert_error
"*ERR*range*"
{
r lpop forbarqaz -123
}
}
test
{
Variadic RPUSH/LPUSH
}
{
r del mylist
...
...
@@ -947,6 +958,12 @@ start_server {
assert_equal
{}
[
r lrange nosuchkey 0 1
]
}
test
{
LRANGE with start > end yields an empty array for backward compatibility
}
{
create_list mylist
"1 2 3"
assert_equal
{}
[
r lrange mylist 1 0
]
assert_equal
{}
[
r lrange mylist -1 -2
]
}
foreach
{
type large
}
[
array get largevalue
]
{
proc trim_list
{
type min max
}
{
upvar 1 large large
...
...
tests/unit/type/stream-cgroups.tcl
View file @
b34fc03e
...
...
@@ -27,7 +27,7 @@ start_server {
# and not the element
"foo bar"
which was pre existing in the
# stream
(
see previous test
)
set reply
[
r XREADGROUP GROUP mygroup c
lient
-1 STREAMS mystream
">"
r XREADGROUP GROUP mygroup c
onsumer
-1 STREAMS mystream
">"
]
assert
{[
llength
[
lindex $reply 0 1
]]
== 2
}
lindex $reply 0 1 0 1
...
...
@@ -39,13 +39,13 @@ start_server {
r XADD mystream * d 4
# Read a few elements using a different consumer name
set reply
[
r XREADGROUP GROUP mygroup c
lient
-2 STREAMS mystream
">"
r XREADGROUP GROUP mygroup c
onsumer
-2 STREAMS mystream
">"
]
assert
{[
llength
[
lindex $reply 0 1
]]
== 2
}
assert
{[
lindex $reply 0 1 0 1
]
eq
{
c 3
}}
set r1
[
r XREADGROUP GROUP mygroup c
lient
-1 COUNT 10 STREAMS mystream 0
]
set r2
[
r XREADGROUP GROUP mygroup c
lient
-2 COUNT 10 STREAMS mystream 0
]
set r1
[
r XREADGROUP GROUP mygroup c
onsumer
-1 COUNT 10 STREAMS mystream 0
]
set r2
[
r XREADGROUP GROUP mygroup c
onsumer
-2 COUNT 10 STREAMS mystream 0
]
assert
{[
lindex $r1 0 1 0 1
]
eq
{
a 1
}}
assert
{[
lindex $r2 0 1 0 1
]
eq
{
c 3
}}
}
...
...
@@ -56,9 +56,9 @@ start_server {
for
{
set j 0
}
{
$j
< 4
}
{
incr j
}
{
set item
[
lindex $pending $j
]
if
{
$j
< 2
}
{
set owner c
lient
-1
set owner c
onsumer
-1
}
else
{
set owner c
lient
-2
set owner c
onsumer
-2
}
assert
{[
lindex $item 1
]
eq $owner
}
assert
{[
lindex $item 1
]
eq $owner
}
...
...
@@ -66,7 +66,7 @@ start_server {
}
test
{
XPENDING can return single consumer items
}
{
set pending
[
r XPENDING mystream mygroup - + 10 c
lient
-1
]
set pending
[
r XPENDING mystream mygroup - + 10 c
onsumer
-1
]
assert
{[
llength $pending
]
== 2
}
}
...
...
@@ -77,9 +77,9 @@ start_server {
test
{
XPENDING with IDLE
}
{
after 20
set pending
[
r XPENDING mystream mygroup IDLE 99999999 - + 10 c
lient
-1
]
set pending
[
r XPENDING mystream mygroup IDLE 99999999 - + 10 c
onsumer
-1
]
assert
{[
llength $pending
]
== 0
}
set pending
[
r XPENDING mystream mygroup IDLE 1 - + 10 c
lient
-1
]
set pending
[
r XPENDING mystream mygroup IDLE 1 - + 10 c
onsumer
-1
]
assert
{[
llength $pending
]
== 2
}
set pending
[
r XPENDING mystream mygroup IDLE 99999999 - + 10
]
assert
{[
llength $pending
]
== 0
}
...
...
@@ -101,12 +101,12 @@ start_server {
}
}
test
{
XACK is able to remove items from the c
lient
/group PEL
}
{
set pending
[
r XPENDING mystream mygroup - + 10 c
lient
-1
]
test
{
XACK is able to remove items from the c
onsumer
/group PEL
}
{
set pending
[
r XPENDING mystream mygroup - + 10 c
onsumer
-1
]
set id1
[
lindex $pending 0 0
]
set id2
[
lindex $pending 1 0
]
assert
{[
r XACK mystream mygroup $id1
]
eq 1
}
set pending
[
r XPENDING mystream mygroup - + 10 c
lient
-1
]
set pending
[
r XPENDING mystream mygroup - + 10 c
onsumer
-1
]
assert
{[
llength $pending
]
== 1
}
set id
[
lindex $pending 0 0
]
assert
{
$id
eq $id2
}
...
...
@@ -242,52 +242,52 @@ start_server {
set id3
[
r XADD mystream * c 3
]
r XGROUP CREATE mystream mygroup 0
# C
lient
1 reads item 1 from the stream without acknowledgements.
# C
lient
2 then claims pending item 1 from the PEL of c
lient
1
# C
onsumer
1 reads item 1 from the stream without acknowledgements.
# C
onsumer
2 then claims pending item 1 from the PEL of c
onsumer
1
set reply
[
r XREADGROUP GROUP mygroup c
lient
1 count 1 STREAMS mystream >
r XREADGROUP GROUP mygroup c
onsumer
1 count 1 STREAMS mystream >
]
assert
{[
llength
[
lindex $reply 0 1 0 1
]]
== 2
}
assert
{[
lindex $reply 0 1 0 1
]
eq
{
a 1
}}
# make sure the entry is present in both the gorup, and the right consumer
assert
{[
llength
[
r XPENDING mystream mygroup - + 10
]]
== 1
}
assert
{[
llength
[
r XPENDING mystream mygroup - + 10 c
lient
1
]]
== 1
}
assert
{[
llength
[
r XPENDING mystream mygroup - + 10 c
lient
2
]]
== 0
}
assert
{[
llength
[
r XPENDING mystream mygroup - + 10 c
onsumer
1
]]
== 1
}
assert
{[
llength
[
r XPENDING mystream mygroup - + 10 c
onsumer
2
]]
== 0
}
r debug sleep 0.2
after 200
set reply
[
r XCLAIM mystream mygroup c
lient
2 10 $id1
r XCLAIM mystream mygroup c
onsumer
2 10 $id1
]
assert
{[
llength
[
lindex $reply 0 1
]]
== 2
}
assert
{[
lindex $reply 0 1
]
eq
{
a 1
}}
# make sure the entry is present in both the gorup, and the right consumer
assert
{[
llength
[
r XPENDING mystream mygroup - + 10
]]
== 1
}
assert
{[
llength
[
r XPENDING mystream mygroup - + 10 c
lient
1
]]
== 0
}
assert
{[
llength
[
r XPENDING mystream mygroup - + 10 c
lient
2
]]
== 1
}
assert
{[
llength
[
r XPENDING mystream mygroup - + 10 c
onsumer
1
]]
== 0
}
assert
{[
llength
[
r XPENDING mystream mygroup - + 10 c
onsumer
2
]]
== 1
}
# C
lient
1 reads another 2 items from stream
r XREADGROUP GROUP mygroup c
lient
1 count 2 STREAMS mystream >
r debug sleep 0.2
# C
onsumer
1 reads another 2 items from stream
r XREADGROUP GROUP mygroup c
onsumer
1 count 2 STREAMS mystream >
after 200
# Delete item 2 from the stream. Now c
lient
1 has PEL that contains
# only item 3. Try to use c
lient
2 to claim the deleted item 2
# from the PEL of c
lient
1, this should return nil
# Delete item 2 from the stream. Now c
onsumer
1 has PEL that contains
# only item 3. Try to use c
onsumer
2 to claim the deleted item 2
# from the PEL of c
onsumer
1, this should return nil
r XDEL mystream $id2
set reply
[
r XCLAIM mystream mygroup c
lient
2 10 $id2
r XCLAIM mystream mygroup c
onsumer
2 10 $id2
]
assert
{[
llength $reply
]
== 1
}
assert_equal
""
[
lindex $reply 0
]
# Delete item 3 from the stream. Now c
lient
1 has PEL that is empty.
# Try to use c
lient
2 to claim the deleted item 3 from the PEL
# of c
lient
1, this should return nil
r debug sleep 0.2
# Delete item 3 from the stream. Now c
onsumer
1 has PEL that is empty.
# Try to use c
onsumer
2 to claim the deleted item 3 from the PEL
# of c
onsumer
1, this should return nil
after 200
r XDEL mystream $id3
set reply
[
r XCLAIM mystream mygroup c
lient
2 10 $id3
r XCLAIM mystream mygroup c
onsumer
2 10 $id3
]
assert
{[
llength $reply
]
== 1
}
assert_equal
""
[
lindex $reply 0
]
...
...
@@ -301,16 +301,16 @@ start_server {
set id3
[
r XADD mystream * c 3
]
r XGROUP CREATE mystream mygroup 0
# C
lient
1 reads item 1 from the stream without acknowledgements.
# C
lient
2 then claims pending item 1 from the PEL of c
lient
1
# C
onsumer
1 reads item 1 from the stream without acknowledgements.
# C
onsumer
2 then claims pending item 1 from the PEL of c
onsumer
1
set reply
[
r XREADGROUP GROUP mygroup c
lient
1 count 1 STREAMS mystream >
r XREADGROUP GROUP mygroup c
onsumer
1 count 1 STREAMS mystream >
]
assert
{[
llength
[
lindex $reply 0 1 0 1
]]
== 2
}
assert
{[
lindex $reply 0 1 0 1
]
eq
{
a 1
}}
r debug sleep 0.2
after 200
set reply
[
r XCLAIM mystream mygroup c
lient
2 10 $id1
r XCLAIM mystream mygroup c
onsumer
2 10 $id1
]
assert
{[
llength
[
lindex $reply 0 1
]]
== 2
}
assert
{[
lindex $reply 0 1
]
eq
{
a 1
}}
...
...
@@ -321,10 +321,10 @@ start_server {
assert
{[
llength
[
lindex $reply 0
]]
== 4
}
assert
{[
lindex $reply 0 3
]
== 2
}
# C
lient
3 then claims pending item 1 from the PEL of c
lient
2 using JUSTID
r debug sleep 0.2
# C
onsumer
3 then claims pending item 1 from the PEL of c
onsumer
2 using JUSTID
after 200
set reply
[
r XCLAIM mystream mygroup c
lient
3 10 $id1 JUSTID
r XCLAIM mystream mygroup c
onsumer
3 10 $id1 JUSTID
]
assert
{[
llength $reply
]
== 1
}
assert
{[
lindex $reply 0
]
eq $id1
}
...
...
@@ -344,17 +344,122 @@ start_server {
set id3
[
r XADD mystream * c 3
]
r XGROUP CREATE mystream mygroup 0
set reply
[
r XREADGROUP GROUP mygroup c
lient
1 count 1 STREAMS mystream >
]
set reply
[
r XREADGROUP GROUP mygroup c
onsumer
1 count 1 STREAMS mystream >
]
assert
{[
llength
[
lindex $reply 0 1 0 1
]]
== 2
}
assert
{[
lindex $reply 0 1 0 1
]
eq
{
a 1
}}
r debug sleep 0.2
after 200
# re-claim with the same consumer that already has it
assert
{[
llength
[
r XCLAIM mystream mygroup c
lient
1 10 $id1
]]
== 1
}
assert
{[
llength
[
r XCLAIM mystream mygroup c
onsumer
1 10 $id1
]]
== 1
}
# make sure the entry is still in the PEL
set reply
[
r XPENDING mystream mygroup - + 10
]
assert
{[
llength $reply
]
== 1
}
assert
{[
lindex $reply 0 1
]
eq
{
client1
}}
assert
{[
lindex $reply 0 1
]
eq
{
consumer1
}}
}
test
{
XAUTOCLAIM can claim PEL items from another consumer
}
{
# Add 3 items into the stream, and create a consumer group
r del mystream
set id1
[
r XADD mystream * a 1
]
set id2
[
r XADD mystream * b 2
]
set id3
[
r XADD mystream * c 3
]
r XGROUP CREATE mystream mygroup 0
# Consumer 1 reads item 1 from the stream without acknowledgements.
# Consumer 2 then claims pending item 1 from the PEL of consumer 1
set reply
[
r XREADGROUP GROUP mygroup consumer1 count 1 STREAMS mystream >
]
assert_equal
[
llength
[
lindex $reply 0 1 0 1
]]
2
assert_equal
[
lindex $reply 0 1 0 1
]
{
a 1
}
after 200
set reply
[
r XAUTOCLAIM mystream mygroup consumer2 10 - COUNT 1
]
assert_equal
[
llength $reply
]
2
assert_equal
[
lindex $reply 0
]
$id1
assert_equal
[
llength
[
lindex $reply 1
]]
1
assert_equal
[
llength
[
lindex $reply 1 0
]]
2
assert_equal
[
llength
[
lindex $reply 1 0 1
]]
2
assert_equal
[
lindex $reply 1 0 1
]
{
a 1
}
# Consumer 1 reads another 2 items from stream
r XREADGROUP GROUP mygroup consumer1 count 2 STREAMS mystream >
# For min-idle-time
after 200
# Delete item 2 from the stream. Now consumer 1 has PEL that contains
# only item 3. Try to use consumer 2 to claim the deleted item 2
# from the PEL of consumer 1, this should return nil
r XDEL mystream $id2
set reply
[
r XAUTOCLAIM mystream mygroup consumer2 10 - COUNT 2
]
# id1 is self-claimed here but not id2
(
'count' was set to 2
)
assert_equal
[
llength $reply
]
2
assert_equal
[
lindex $reply 0
]
$id2
assert_equal
[
llength
[
lindex $reply 1
]]
2
assert_equal
[
llength
[
lindex $reply 1 0
]]
2
assert_equal
[
llength
[
lindex $reply 1 0 1
]]
2
assert_equal
[
lindex $reply 1 0 1
]
{
a 1
}
assert_equal
[
lindex $reply 1 1
]
""
# Delete item 3 from the stream. Now consumer 1 has PEL that is empty.
# Try to use consumer 2 to claim the deleted item 3 from the PEL
# of consumer 1, this should return nil
after 200
r XDEL mystream $id3
set reply
[
r XAUTOCLAIM mystream mygroup consumer2 10 - JUSTID
]
# id1 is self-claimed here but not id2 and id3
(
'count' is default 100
)
# we also test the JUSTID modifier here. note that, when using JUSTID,
# deleted entries are returned in reply
(
consistent with XCLAIM
)
.
assert_equal
[
llength $reply
]
2
assert_equal
[
lindex $reply 0
]
"0-0"
assert_equal
[
llength
[
lindex $reply 1
]]
3
assert_equal
[
lindex $reply 1 0
]
$id1
assert_equal
[
lindex $reply 1 1
]
$id2
assert_equal
[
lindex $reply 1 2
]
$id3
}
test
{
XAUTOCLAIM as an iterator
}
{
# Add 5 items into the stream, and create a consumer group
r del mystream
set id1
[
r XADD mystream * a 1
]
set id2
[
r XADD mystream * b 2
]
set id3
[
r XADD mystream * c 3
]
set id4
[
r XADD mystream * d 4
]
set id5
[
r XADD mystream * e 5
]
r XGROUP CREATE mystream mygroup 0
# Read 5 messages into consumer1
r XREADGROUP GROUP mygroup consumer1 count 90 STREAMS mystream >
# For min-idle-time
after 200
# Claim 2 entries
set reply
[
r XAUTOCLAIM mystream mygroup consumer2 10 - COUNT 2
]
assert_equal
[
llength $reply
]
2
set cursor
[
lindex $reply 0
]
assert_equal $cursor $id2
assert_equal
[
llength
[
lindex $reply 1
]]
2
assert_equal
[
llength
[
lindex $reply 1 0 1
]]
2
assert_equal
[
lindex $reply 1 0 1
]
{
a 1
}
# Claim 2 more entries
set reply
[
r XAUTOCLAIM mystream mygroup consumer2 10
(
$cursor
COUNT 2
]
assert_equal
[
llength $reply
]
2
set cursor
[
lindex $reply 0
]
assert_equal $cursor $id4
assert_equal
[
llength
[
lindex $reply 1
]]
2
assert_equal
[
llength
[
lindex $reply 1 0 1
]]
2
assert_equal
[
lindex $reply 1 0 1
]
{
c 3
}
# Claim last entry
set reply
[
r XAUTOCLAIM mystream mygroup consumer2 10
(
$cursor
COUNT 2
]
assert_equal
[
llength $reply
]
2
set cursor
[
lindex $reply 0
]
assert_equal $cursor
{
0-0
}
assert_equal
[
llength
[
lindex $reply 1
]]
1
assert_equal
[
llength
[
lindex $reply 1 0 1
]]
2
assert_equal
[
lindex $reply 1 0 1
]
{
e 5
}
}
test
{
XINFO FULL output
}
{
...
...
@@ -477,7 +582,7 @@ start_server {
assert
{
$curr
_grpinfo == $grpinfo
}
set n_consumers
[
lindex $grpinfo 3
]
# Bob should be created only when there will be new data for this c
lient
# Bob should be created only when there will be new data for this c
onsumer
assert_equal $n_consumers 2
set reply
[
r xinfo consumers mystream mygroup
]
set consumer_info
[
lindex $reply 0
]
...
...
tests/unit/type/stream.tcl
View file @
b34fc03e
...
...
@@ -94,6 +94,7 @@ start_server {
r XADD mystream MAXLEN 5 * yitem $j
}
}
assert
{[
r xlen mystream
]
== 5
}
set res
[
r xrange mystream - +
]
set expected 995
foreach r $res
{
...
...
@@ -138,6 +139,39 @@ start_server {
assert_equal
[
lindex $items 1 1
]
{
item 2 value b
}
}
test
{
XADD with MINID option
}
{
r DEL mystream
for
{
set j 1
}
{
$j
< 1001
}
{
incr j
}
{
set minid 1000
if
{
$j
>= 5
}
{
set minid
[
expr
{
$j-5
}]
}
if
{
rand
()
< 0.9
}
{
r XADD mystream MINID $minid $j xitem $j
}
else
{
r XADD mystream MINID $minid $j yitem $j
}
}
assert
{[
r xlen mystream
]
== 6
}
set res
[
r xrange mystream - +
]
set expected 995
foreach r $res
{
assert
{[
lindex $r 1 1
]
== $expected
}
incr expected
}
}
test
{
XTRIM with MINID option
}
{
r DEL mystream
r XADD mystream 1-0 f v
r XADD mystream 2-0 f v
r XADD mystream 3-0 f v
r XADD mystream 4-0 f v
r XADD mystream 5-0 f v
r XTRIM mystream MINID = 3-0
assert_equal
[
r XRANGE mystream - +
]
{{
3-0
{
f v
}}
{
4-0
{
f v
}}
{
5-0
{
f v
}}}
}
test
{
XADD mass insertion and XLEN
}
{
r DEL mystream
r multi
...
...
@@ -448,7 +482,49 @@ start_server {
assert
{[
r XLEN mystream
]
== 400
}
}
test
{
XADD with LIMIT consecutive calls
}
{
r del mystream
r config set stream-node-max-entries 10
for
{
set j 0
}
{
$j
< 100
}
{
incr j
}
{
r XADD mystream * xitem v
}
r XADD mystream MAXLEN ~ 55 LIMIT 30 * xitem v
assert
{[
r xlen mystream
]
== 71
}
r XADD mystream MAXLEN ~ 55 LIMIT 30 * xitem v
assert
{[
r xlen mystream
]
== 62
}
r config set stream-node-max-entries 100
}
test
{
XTRIM with ~ is limited
}
{
r del mystream
r config set stream-node-max-entries 1
for
{
set j 0
}
{
$j
< 102
}
{
incr j
}
{
r XADD mystream * xitem v
}
r XTRIM mystream MAXLEN ~ 1
assert
{[
r xlen mystream
]
== 2
}
r config set stream-node-max-entries 100
}
test
{
XTRIM without ~ is not limited
}
{
r del mystream
r config set stream-node-max-entries 1
for
{
set j 0
}
{
$j
< 102
}
{
incr j
}
{
r XADD mystream * xitem v
}
r XTRIM mystream MAXLEN 1
assert
{[
r xlen mystream
]
== 1
}
r config set stream-node-max-entries 100
}
test
{
XTRIM without ~ and with LIMIT
}
{
r del mystream
r config set stream-node-max-entries 1
for
{
set j 0
}
{
$j
< 102
}
{
incr j
}
{
r XADD mystream * xitem v
}
assert_error ERR*
{
r XTRIM mystream MAXLEN 1 LIMIT 30
}
}
}
start_server
{
tags
{
"stream"
}
overrides
{
appendonly yes
}}
{
...
...
@@ -466,6 +542,22 @@ start_server {tags {"stream"} overrides {appendonly yes}} {
}
}
start_server
{
tags
{
"stream"
}
overrides
{
appendonly yes
}}
{
test
{
XADD with MINID > lastid can propagate correctly
}
{
for
{
set j 0
}
{
$j
< 100
}
{
incr j
}
{
set id
[
expr
{
$j
+1
}]
r XADD mystream $id xitem v
}
r XADD mystream MINID 1 * xitem v
incr j
assert
{[
r xlen mystream
]
== $j
}
r debug loadaof
r XADD mystream * xitem v
incr j
assert
{[
r xlen mystream
]
== $j
}
}
}
start_server
{
tags
{
"stream"
}
overrides
{
appendonly yes
}}
{
test
{
XADD with ~ MAXLEN can propagate correctly
}
{
for
{
set j 0
}
{
$j
< 100
}
{
incr j
}
{
...
...
@@ -482,6 +574,52 @@ start_server {tags {"stream"} overrides {appendonly yes}} {
}
}
start_server
{
tags
{
"stream"
}
overrides
{
appendonly yes stream-node-max-entries 10
}}
{
test
{
XADD with ~ MAXLEN and LIMIT can propagate correctly
}
{
for
{
set j 0
}
{
$j
< 100
}
{
incr j
}
{
r XADD mystream * xitem v
}
r XADD mystream MAXLEN ~ 55 LIMIT 30 * xitem v
assert
{[
r xlen mystream
]
== 71
}
r config set stream-node-max-entries 1
r debug loadaof
r XADD mystream * xitem v
assert
{[
r xlen mystream
]
== 72
}
}
}
start_server
{
tags
{
"stream"
}
overrides
{
appendonly yes
}}
{
test
{
XADD with ~ MINID can propagate correctly
}
{
for
{
set j 0
}
{
$j
< 100
}
{
incr j
}
{
set id
[
expr
{
$j
+1
}]
r XADD mystream $id xitem v
}
r XADD mystream MINID ~ $j * xitem v
incr j
assert
{[
r xlen mystream
]
== $j
}
r config set stream-node-max-entries 1
r debug loadaof
r XADD mystream * xitem v
incr j
assert
{[
r xlen mystream
]
== $j
}
}
}
start_server
{
tags
{
"stream"
}
overrides
{
appendonly yes stream-node-max-entries 10
}}
{
test
{
XADD with ~ MINID and LIMIT can propagate correctly
}
{
for
{
set j 0
}
{
$j
< 100
}
{
incr j
}
{
set id
[
expr
{
$j
+1
}]
r XADD mystream $id xitem v
}
r XADD mystream MINID ~ 55 LIMIT 30 * xitem v
assert
{[
r xlen mystream
]
== 71
}
r config set stream-node-max-entries 1
r debug loadaof
r XADD mystream * xitem v
assert
{[
r xlen mystream
]
== 72
}
}
}
start_server
{
tags
{
"stream"
}
overrides
{
appendonly yes stream-node-max-entries 10
}}
{
test
{
XTRIM with ~ MAXLEN can propagate correctly
}
{
for
{
set j 0
}
{
$j
< 100
}
{
incr j
}
{
...
...
tests/unit/type/zset.tcl
View file @
b34fc03e
...
...
@@ -1472,4 +1472,86 @@ start_server {tags {"zset"}} {
}
r config set zset-max-ziplist-entries $original_max
}
test
{
ZRANGESTORE basic
}
{
r flushall
r zadd z1 1 a 2 b 3 c 4 d
set res
[
r zrangestore z2 z1 0 -1
]
assert_equal $res 4
r zrange z2 0 -1 withscores
}
{
a 1 b 2 c 3 d 4
}
test
{
ZRANGESTORE range
}
{
set res
[
r zrangestore z2 z1 1 2
]
assert_equal $res 2
r zrange z2 0 -1 withscores
}
{
b 2 c 3
}
test
{
ZRANGESTORE BYLEX
}
{
set res
[
r zrangestore z2 z1
\[
b
\[
c BYLEX
]
assert_equal $res 2
r zrange z2 0 -1 withscores
}
{
b 2 c 3
}
test
{
ZRANGESTORE BYSCORE
}
{
set res
[
r zrangestore z2 z1 1 2 BYSCORE
]
assert_equal $res 2
r zrange z2 0 -1 withscores
}
{
a 1 b 2
}
test
{
ZRANGESTORE BYSCORE LIMIT
}
{
set res
[
r zrangestore z2 z1 0 5 BYSCORE LIMIT 0 2
]
assert_equal $res 2
r zrange z2 0 -1 withscores
}
{
a 1 b 2
}
test
{
ZRANGESTORE BYSCORE REV LIMIT
}
{
set res
[
r zrangestore z2 z1 5 0 BYSCORE REV LIMIT 0 2
]
assert_equal $res 2
r zrange z2 0 -1 withscores
}
{
c 3 d 4
}
test
{
ZRANGE BYSCORE REV LIMIT
}
{
r zrange z1 5 0 BYSCORE REV LIMIT 0 2 WITHSCORES
}
{
d 4 c 3
}
test
{
ZRANGESTORE - empty range
}
{
set res
[
r zrangestore z2 z1 5 6
]
assert_equal $res 0
r exists z2
}
{
0
}
test
{
ZRANGESTORE BYLEX - empty range
}
{
set res
[
r zrangestore z2 z1
\[
f
\[
g BYLEX
]
assert_equal $res 0
r exists z2
}
{
0
}
test
{
ZRANGESTORE BYSCORE - empty range
}
{
set res
[
r zrangestore z2 z1 5 6 BYSCORE
]
assert_equal $res 0
r exists z2
}
{
0
}
test
{
ZRANGE BYLEX
}
{
r zrange z1
\[
b
\[
c BYLEX
}
{
b c
}
test
{
ZRANGESTORE invalid syntax
}
{
catch
{
r zrangestore z2 z1 0 -1 limit 1 2
}
err
assert_match
"*syntax*"
$err
catch
{
r zrangestore z2 z1 0 -1 WITHSCORES
}
err
assert_match
"*syntax*"
$err
}
test
{
ZRANGE invalid syntax
}
{
catch
{
r zrange z1 0 -1 limit 1 2
}
err
assert_match
"*syntax*"
$err
catch
{
r zrange z1 0 -1 BYLEX WITHSCORES
}
err
assert_match
"*syntax*"
$err
catch
{
r zrevrange z1 0 -1 BYSCORE
}
err
assert_match
"*syntax*"
$err
catch
{
r zrangebyscore z1 0 -1 REV
}
err
assert_match
"*syntax*"
$err
}
}
tests/unit/wait.tcl
View file @
b34fc03e
...
...
@@ -5,6 +5,7 @@ start_server {} {
set slave
[
srv 0 client
]
set slave_host
[
srv 0 host
]
set slave_port
[
srv 0 port
]
set slave_pid
[
srv 0 pid
]
set master
[
srv -1 client
]
set master_host
[
srv -1 host
]
set master_port
[
srv -1 port
]
...
...
@@ -33,13 +34,25 @@ start_server {} {
}
test
{
WAIT should not acknowledge 1 additional copy if slave is blocked
}
{
set cmd
[
rediscli $slave_host $slave_port
"debug sleep 5"
]
exec
{*}
$cmd
> /dev/null 2> /dev/null &
after 1000
;
# Give redis-cli the time to execute the command.
exec kill -SIGSTOP $slave_pid
$master set foo 0
$master incr foo
$master incr foo
$master incr foo
assert
{[
$master
wait 1 3000
]
== 0
}
assert
{[
$master
wait 1 1000
]
== 0
}
exec kill -SIGCONT $slave_pid
assert
{[
$master
wait 1 1000
]
== 1
}
}
test
{
WAIT implicitly blocks on client pause since ACKs aren't sent
}
{
exec kill -SIGSTOP $slave_pid
$master multi
$master incr foo
$master client pause 10000 write
$master exec
assert
{[
$master
wait 1 1000
]
== 0
}
$master client unpause
exec kill -SIGCONT $slave_pid
assert
{[
$master
wait 1 1000
]
== 1
}
}
}}
Prev
1
2
3
4
5
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