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)}
99 set path
[expr {int
(rand
()*[llength $args])}]
100 uplevel 1 [lindex $args $path]
103 proc randomValue
{} {
105 # Small enough to likely collide
108 # 32 bit compressible signed/unsigned
109 randpath
{randomInt
2000000000} {randomInt
4000000000}
112 randpath
{randomInt
1000000000000}
115 randpath
{randstring
0 256 alpha
} \
116 {randstring
0 256 compr
} \
117 {randstring
0 256 binary}
123 # Small enough to likely collide
126 # 32 bit compressible signed/unsigned
127 randpath
{randomInt
2000000000} {randomInt
4000000000}
130 randpath
{randomInt
1000000000000}
133 randpath
{randstring
1 256 alpha
} \
134 {randstring
1 256 compr
}
138 proc findKeyWithType
{r type
} {
139 for {set j
0} {$j < 20} {incr j
} {
140 set k
[{*}$r randomkey
]
144 if {[{*}$r type
$k] eq
$type} {
151 proc createComplexDataset
{r ops
{opt
{}}} {
152 for {set j
0} {$j < $ops} {incr j
} {
158 if {[lsearch -exact $opt useexpire
] != -1} {
160 {*}$r expire
[randomKey
] [randomInt
2]
165 set d
[expr {rand
()}]
167 set d
[expr {rand
()}]
169 set d
[expr {rand
()}]
171 set d
[expr {rand
()}]
173 set d
[expr {rand
()}]
175 randpath
{set d
+inf
} {set d
-inf}
177 set t
[{*}$r type
$k]
193 set t
[{*}$r type
$k]
201 randpath
{{*}$r lpush
$k $v} \
202 {{*}$r rpush
$k $v} \
203 {{*}$r lrem
$k 0 $v} \
208 randpath
{{*}$r sadd
$k $v} \
211 set otherset
[findKeyWithType
{*}$r set]
212 if {$otherset ne
{}} {
214 {*}$r sunionstore
$k2 $k $otherset
216 {*}$r sinterstore
$k2 $k $otherset
218 {*}$r sdiffstore
$k2 $k $otherset
224 randpath
{{*}$r zadd
$k $d $v} \
227 set otherzset
[findKeyWithType
{*}$r zset
]
228 if {$otherzset ne
{}} {
230 {*}$r zunionstore
$k2 2 $k $otherzset
232 {*}$r zinterstore
$k2 2 $k $otherzset
238 randpath
{{*}$r hset
$k $f $v} \
245 proc formatCommand
{args
} {
246 set cmd
"*[llength $args]\r\n"
248 append cmd
"$[string length $a]\r\n$a\r\n"
255 foreach k
[lsort [{*}$r keys
*]] {
256 set type
[{*}$r type
$k]
257 append o
[csvstring
$k] , [csvstring
$type] ,
260 append o
[csvstring
[{*}$r get
$k]] "\n"
263 foreach e
[{*}$r lrange $k 0 -1] {
264 append o
[csvstring
$e] ,
269 foreach e
[lsort [{*}$r smembers
$k]] {
270 append o
[csvstring
$e] ,
275 foreach e
[{*}$r zrange
$k 0 -1 withscores
] {
276 append o
[csvstring
$e] ,
281 set fields
[{*}$r hgetall
$k]
283 foreach {k v
} $fields {
284 lappend newfields
[list $k $v]
286 set fields
[lsort -index 0 $newfields]
288 append o
[csvstring
[lindex $kv 0]] ,
289 append o
[csvstring
[lindex $kv 1]] ,