1 proc randstring
{min max
{type
binary}} {
2 set len
[expr {$min+int
(rand
()*($max-$min+1))}]
4 if {$type eq
{binary}} {
7 } elseif
{$type eq
{alpha
}} {
10 } elseif
{$type eq
{compr
}} {
15 append output
[format "%c" [expr {$minval+int
(rand
()*($maxval-$minval+1))}]]
21 # Useful for some test
22 proc zlistAlikeSort
{a b
} {
23 if {[lindex $a 0] > [lindex $b 0]} {return 1}
24 if {[lindex $a 0] < [lindex $b 0]} {return -1}
25 string compare
[lindex $a 1] [lindex $b 1]
28 # Return all log lines starting with the first line that contains a warning.
29 # Generally, this will be an assertion error with a stack trace.
30 proc warnings_from_file
{filename} {
31 set lines
[split [exec cat
$filename] "\n"]
35 if {[regexp {^
\[\d
+\]\s
+\d
+\s
+\w
+\s
+\d
{2}:\d
{2}:\d
{2} \#} $line]} {
45 # Return value for INFO property
46 proc status
{r property
} {
47 if {[regexp "\r\n$property:(.*?)\r\n" [{*}$r info] _ value
]} {
52 proc waitForBgsave r
{
54 if {[status r bgsave_in_progress
] eq
1} {
55 puts -nonewline "\nWaiting for background save to finish... "
64 proc waitForBgrewriteaof r
{
66 if {[status r bgrewriteaof_in_progress
] eq
1} {
67 puts -nonewline "\nWaiting for background AOF rewrite to finish... "
76 proc wait_for_sync r
{
78 if {[status r master_link_status
] eq
"down"} {
86 proc randomInt
{max
} {
87 expr {int
(rand
()*$max)}
91 set path
[expr {int
(rand
()*[llength $args])}]
92 uplevel 1 [lindex $args $path]
97 # Small enough to likely collide
100 # 32 bit compressible signed/unsigned
101 randpath
{randomInt
2000000000} {randomInt
4000000000}
104 randpath
{randomInt
1000000000000}
107 randpath
{randstring
0 256 alpha
} \
108 {randstring
0 256 compr
} \
109 {randstring
0 256 binary}
115 # Small enough to likely collide
118 # 32 bit compressible signed/unsigned
119 randpath
{randomInt
2000000000} {randomInt
4000000000}
122 randpath
{randomInt
1000000000000}
125 randpath
{randstring
1 256 alpha
} \
126 {randstring
1 256 compr
}
130 proc findKeyWithType
{r type
} {
131 for {set j
0} {$j < 20} {incr j
} {
132 set k
[{*}$r randomkey
]
136 if {[{*}$r type
$k] eq
$type} {
143 proc createComplexDataset
{r ops
{opt
{}}} {
144 for {set j
0} {$j < $ops} {incr j
} {
150 if {[lsearch -exact $opt useexpire
] != -1} {
152 {*}$r expire
[randomKey
] [randomInt
2]
157 set d
[expr {rand
()}]
159 set d
[expr {rand
()}]
161 set d
[expr {rand
()}]
163 set d
[expr {rand
()}]
165 set d
[expr {rand
()}]
167 randpath
{set d
+inf
} {set d
-inf}
169 set t
[{*}$r type
$k]
185 set t
[{*}$r type
$k]
193 randpath
{{*}$r lpush
$k $v} \
194 {{*}$r rpush
$k $v} \
195 {{*}$r lrem
$k 0 $v} \
200 randpath
{{*}$r sadd
$k $v} \
203 set otherset
[findKeyWithType r
set]
204 if {$otherset ne
{}} {
206 {*}$r sunionstore
$k2 $k $otherset
208 {*}$r sinterstore
$k2 $k $otherset
210 {*}$r sdiffstore
$k2 $k $otherset
216 randpath
{{*}$r zadd
$k $d $v} \
219 set otherzset
[findKeyWithType r zset
]
220 if {$otherzset ne
{}} {
222 {*}$r zunionstore
$k2 2 $k $otherzset
224 {*}$r zinterstore
$k2 2 $k $otherzset
230 randpath
{{*}$r hset
$k $f $v} \
237 proc formatCommand
{args
} {
238 set cmd
"*[llength $args]\r\n"
240 append cmd
"$[string length $a]\r\n$a\r\n"
247 foreach k
[lsort [{*}$r keys
*]] {
248 set type
[{*}$r type
$k]
249 append o
[csvstring
$k] , [csvstring
$type] ,
252 append o
[csvstring
[{*}$r get
$k]] "\n"
255 foreach e
[{*}$r lrange $k 0 -1] {
256 append o
[csvstring
$e] ,
261 foreach e
[lsort [{*}$r smembers
$k]] {
262 append o
[csvstring
$e] ,
267 foreach e
[{*}$r zrange
$k 0 -1 withscores
] {
268 append o
[csvstring
$e] ,
273 set fields
[{*}$r hgetall
$k]
275 foreach {k v
} $fields {
276 lappend newfields
[list $k $v]
278 set fields
[lsort -index 0 $newfields]
280 append o
[csvstring
[lindex $kv 0]] ,
281 append o
[csvstring
[lindex $kv 1]] ,