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
} {
144 for {set j
0} {$j < $ops} {incr j
} {
150 set d
[expr {rand
()}]
152 set d
[expr {rand
()}]
154 set d
[expr {rand
()}]
156 set d
[expr {rand
()}]
158 set d
[expr {rand
()}]
160 randpath
{set d
+inf
} {set d
-inf}
162 set t
[{*}$r type
$k]
178 set t
[{*}$r type
$k]
186 randpath
{{*}$r lpush
$k $v} \
187 {{*}$r rpush
$k $v} \
188 {{*}$r lrem
$k 0 $v} \
193 randpath
{{*}$r sadd
$k $v} \
196 set otherset
[findKeyWithType r
set]
197 if {$otherset ne
{}} {
199 {*}$r sunionstore
$k2 $k $otherset
201 {*}$r sinterstore
$k2 $k $otherset
203 {*}$r sdiffstore
$k2 $k $otherset
209 randpath
{{*}$r zadd
$k $d $v} \
212 set otherzset
[findKeyWithType r zset
]
213 if {$otherzset ne
{}} {
215 {*}$r zunionstore
$k2 2 $k $otherzset
217 {*}$r zinterstore
$k2 2 $k $otherzset
223 randpath
{{*}$r hset
$k $f $v} \
230 proc formatCommand
{args
} {
231 set cmd
"*[llength $args]\r\n"
233 append cmd
"$[string length $a]\r\n$a\r\n"
240 foreach k
[lsort [{*}$r keys
*]] {
241 set type
[{*}$r type
$k]
242 append o
[csvstring
$k] , [csvstring
$type] ,
245 append o
[csvstring
[{*}$r get
$k]] "\n"
248 foreach e
[{*}$r lrange $k 0 -1] {
249 append o
[csvstring
$e] ,
254 foreach e
[lsort [{*}$r smembers
$k]] {
255 append o
[csvstring
$e] ,
260 foreach e
[{*}$r zrange
$k 0 -1 withscores
] {
261 append o
[csvstring
$e] ,
266 set fields
[{*}$r hgetall
$k]
268 foreach {k v
} $fields {
269 lappend newfields
[list $k $v]
271 set fields
[lsort -index 0 $newfields]
273 append o
[csvstring
[lindex $kv 0]] ,
274 append o
[csvstring
[lindex $kv 1]] ,