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} {
56 puts -nonewline "\nWaiting for background save to finish... "
66 proc waitForBgrewriteaof r
{
68 if {[status r bgrewriteaof_in_progress
] eq
1} {
70 puts -nonewline "\nWaiting for background AOF rewrite to finish... "
80 proc wait_for_sync r
{
82 if {[status r master_link_status
] eq
"down"} {
90 proc randomInt
{max
} {
91 expr {int
(rand
()*$max)}
95 set path
[expr {int
(rand
()*[llength $args])}]
96 uplevel 1 [lindex $args $path]
101 # Small enough to likely collide
104 # 32 bit compressible signed/unsigned
105 randpath
{randomInt
2000000000} {randomInt
4000000000}
108 randpath
{randomInt
1000000000000}
111 randpath
{randstring
0 256 alpha
} \
112 {randstring
0 256 compr
} \
113 {randstring
0 256 binary}
119 # Small enough to likely collide
122 # 32 bit compressible signed/unsigned
123 randpath
{randomInt
2000000000} {randomInt
4000000000}
126 randpath
{randomInt
1000000000000}
129 randpath
{randstring
1 256 alpha
} \
130 {randstring
1 256 compr
}
134 proc findKeyWithType
{r type
} {
135 for {set j
0} {$j < 20} {incr j
} {
136 set k
[{*}$r randomkey
]
140 if {[{*}$r type
$k] eq
$type} {
147 proc createComplexDataset
{r ops
{opt
{}}} {
148 for {set j
0} {$j < $ops} {incr j
} {
154 if {[lsearch -exact $opt useexpire
] != -1} {
156 {*}$r expire
[randomKey
] [randomInt
2]
161 set d
[expr {rand
()}]
163 set d
[expr {rand
()}]
165 set d
[expr {rand
()}]
167 set d
[expr {rand
()}]
169 set d
[expr {rand
()}]
171 randpath
{set d
+inf
} {set d
-inf}
173 set t
[{*}$r type
$k]
189 set t
[{*}$r type
$k]
197 randpath
{{*}$r lpush
$k $v} \
198 {{*}$r rpush
$k $v} \
199 {{*}$r lrem
$k 0 $v} \
204 randpath
{{*}$r sadd
$k $v} \
207 set otherset
[findKeyWithType
{*}$r set]
208 if {$otherset ne
{}} {
210 {*}$r sunionstore
$k2 $k $otherset
212 {*}$r sinterstore
$k2 $k $otherset
214 {*}$r sdiffstore
$k2 $k $otherset
220 randpath
{{*}$r zadd
$k $d $v} \
223 set otherzset
[findKeyWithType
{*}$r zset
]
224 if {$otherzset ne
{}} {
226 {*}$r zunionstore
$k2 2 $k $otherzset
228 {*}$r zinterstore
$k2 2 $k $otherzset
234 randpath
{{*}$r hset
$k $f $v} \
241 proc formatCommand
{args
} {
242 set cmd
"*[llength $args]\r\n"
244 append cmd
"$[string length $a]\r\n$a\r\n"
251 foreach k
[lsort [{*}$r keys
*]] {
252 set type
[{*}$r type
$k]
253 append o
[csvstring
$k] , [csvstring
$type] ,
256 append o
[csvstring
[{*}$r get
$k]] "\n"
259 foreach e
[{*}$r lrange $k 0 -1] {
260 append o
[csvstring
$e] ,
265 foreach e
[lsort [{*}$r smembers
$k]] {
266 append o
[csvstring
$e] ,
271 foreach e
[{*}$r zrange
$k 0 -1 withscores
] {
272 append o
[csvstring
$e] ,
277 set fields
[{*}$r hgetall
$k]
279 foreach {k v
} $fields {
280 lappend newfields
[list $k $v]
282 set fields
[lsort -index 0 $newfields]
284 append o
[csvstring
[lindex $kv 0]] ,
285 append o
[csvstring
[lindex $kv 1]] ,