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"]
36 if {[string match
{*REDIS BUG REPORT START
*} $line]} {
39 if {[regexp {^
\[\d
+\]\s
+\d
+\s
+\w
+\s
+\d
{2}:\d
{2}:\d
{2} \#} $line]} {
42 if {$logall ||
$matched} {
49 # Return value for INFO property
50 proc status
{r property
} {
51 if {[regexp "\r\n$property:(.*?)\r\n" [{*}$r info] _ value
]} {
56 proc waitForBgsave r
{
58 if {[status r rdb_bgsave_in_progress
] eq
1} {
60 puts -nonewline "\nWaiting for background save to finish... "
70 proc waitForBgrewriteaof r
{
72 if {[status r aof_rewrite_in_progress
] eq
1} {
74 puts -nonewline "\nWaiting for background AOF rewrite to finish... "
84 proc wait_for_sync r
{
86 if {[status
$r master_link_status
] eq
"down"} {
94 proc randomInt
{max
} {
95 expr {int
(rand
()*$max)}
98 proc randomSignedInt
{max
} {
99 set i
[randomInt
$max]
107 set path
[expr {int
(rand
()*[llength $args])}]
108 uplevel 1 [lindex $args $path]
111 proc randomValue
{} {
113 # Small enough to likely collide
116 # 32 bit compressible signed/unsigned
117 randpath
{randomSignedInt
2000000000} {randomSignedInt
4000000000}
120 randpath
{randomSignedInt
1000000000000}
123 randpath
{randstring
0 256 alpha
} \
124 {randstring
0 256 compr
} \
125 {randstring
0 256 binary}
131 # Small enough to likely collide
134 # 32 bit compressible signed/unsigned
135 randpath
{randomInt
2000000000} {randomInt
4000000000}
138 randpath
{randomInt
1000000000000}
141 randpath
{randstring
1 256 alpha
} \
142 {randstring
1 256 compr
}
146 proc findKeyWithType
{r type
} {
147 for {set j
0} {$j < 20} {incr j
} {
148 set k
[{*}$r randomkey
]
152 if {[{*}$r type
$k] eq
$type} {
159 proc createComplexDataset
{r ops
{opt
{}}} {
160 for {set j
0} {$j < $ops} {incr j
} {
166 if {[lsearch -exact $opt useexpire
] != -1} {
168 {*}$r expire
[randomKey
] [randomInt
2]
173 set d
[expr {rand
()}]
175 set d
[expr {rand
()}]
177 set d
[expr {rand
()}]
179 set d
[expr {rand
()}]
181 set d
[expr {rand
()}]
183 randpath
{set d
+inf
} {set d
-inf}
185 set t
[{*}$r type
$k]
201 set t
[{*}$r type
$k]
209 randpath
{{*}$r lpush
$k $v} \
210 {{*}$r rpush
$k $v} \
211 {{*}$r lrem
$k 0 $v} \
216 randpath
{{*}$r sadd
$k $v} \
219 set otherset
[findKeyWithType
{*}$r set]
220 if {$otherset ne
{}} {
222 {*}$r sunionstore
$k2 $k $otherset
224 {*}$r sinterstore
$k2 $k $otherset
226 {*}$r sdiffstore
$k2 $k $otherset
232 randpath
{{*}$r zadd
$k $d $v} \
235 set otherzset
[findKeyWithType
{*}$r zset
]
236 if {$otherzset ne
{}} {
238 {*}$r zunionstore
$k2 2 $k $otherzset
240 {*}$r zinterstore
$k2 2 $k $otherzset
246 randpath
{{*}$r hset
$k $f $v} \
253 proc formatCommand
{args
} {
254 set cmd
"*[llength $args]\r\n"
256 append cmd
"$[string length $a]\r\n$a\r\n"
263 foreach k
[lsort [{*}$r keys
*]] {
264 set type
[{*}$r type
$k]
265 append o
[csvstring
$k] , [csvstring
$type] ,
268 append o
[csvstring
[{*}$r get
$k]] "\n"
271 foreach e
[{*}$r lrange $k 0 -1] {
272 append o
[csvstring
$e] ,
277 foreach e
[lsort [{*}$r smembers
$k]] {
278 append o
[csvstring
$e] ,
283 foreach e
[{*}$r zrange
$k 0 -1 withscores
] {
284 append o
[csvstring
$e] ,
289 set fields
[{*}$r hgetall
$k]
291 foreach {k v
} $fields {
292 lappend newfields
[list $k $v]
294 set fields
[lsort -index 0 $newfields]
296 append o
[csvstring
[lindex $kv 0]] ,
297 append o
[csvstring
[lindex $kv 1]] ,