]> git.saurik.com Git - redis.git/blame - test-redis.tcl
GETSET tests
[redis.git] / test-redis.tcl
CommitLineData
ed9b544e 1# TODO # test pipelining
2
43c9dc7b 3source client-libraries/tcl/redis.tcl
4
ed9b544e 5set ::passed 0
6set ::failed 0
7
8proc test {name code okpattern} {
9 puts -nonewline [format "%-70s " $name]
10 flush stdout
11 set retval [uplevel 1 $code]
12 if {$okpattern eq $retval || [string match $okpattern $retval]} {
13 puts "PASSED"
14 incr ::passed
15 } else {
16 puts "!! ERROR expected\n'$okpattern'\nbut got\n'$retval'"
17 incr ::failed
18 }
19}
20
21proc main {server port} {
43c9dc7b 22 set r [redis $server $port]
23 set err ""
ed9b544e 24
abcb223e
BH
25 # The following AUTH test should be enabled only when requirepass
26 # <PASSWORD> is set in redis.conf and redis-server was started with
27 # redis.conf as the first argument.
28
29 #test {AUTH with requirepass in redis.conf} {
30 # $r auth foobared
31 #} {OK}
32
ed9b544e 33 test {DEL all keys to start with a clean DB} {
43c9dc7b 34 foreach key [$r keys *] {$r del $key}
35 $r dbsize
ed9b544e 36 } {0}
37
38 test {SET and GET an item} {
43c9dc7b 39 $r set x foobar
40 $r get x
ed9b544e 41 } {foobar}
42
43 test {DEL against a single item} {
43c9dc7b 44 $r del x
45 $r get x
ed9b544e 46 } {}
47
48 test {KEYS with pattern} {
49 foreach key {key_x key_y key_z foo_a foo_b foo_c} {
43c9dc7b 50 $r set $key hello
ed9b544e 51 }
43c9dc7b 52 lsort [$r keys foo*]
ed9b544e 53 } {foo_a foo_b foo_c}
54
55 test {KEYS to get all keys} {
43c9dc7b 56 lsort [$r keys *]
ed9b544e 57 } {foo_a foo_b foo_c key_x key_y key_z}
58
59 test {DBSIZE} {
43c9dc7b 60 $r dbsize
ed9b544e 61 } {6}
62
63 test {DEL all keys} {
43c9dc7b 64 foreach key [$r keys *] {$r del $key}
65 $r dbsize
ed9b544e 66 } {0}
67
68 test {Very big payload in GET/SET} {
69 set buf [string repeat "abcd" 1000000]
43c9dc7b 70 $r set foo $buf
71 $r get foo
ed9b544e 72 } [string repeat "abcd" 1000000]
73
74 test {SET 10000 numeric keys and access all them in reverse order} {
75 for {set x 0} {$x < 10000} {incr x} {
43c9dc7b 76 $r set $x $x
ed9b544e 77 }
78 set sum 0
79 for {set x 9999} {$x >= 0} {incr x -1} {
43c9dc7b 80 incr sum [$r get $x]
ed9b544e 81 }
82 format $sum
83 } {49995000}
84
85 test {DBSIZE should be 10001 now} {
43c9dc7b 86 $r dbsize
ed9b544e 87 } {10001}
88
89 test {INCR against non existing key} {
90 set res {}
43c9dc7b 91 append res [$r incr novar]
92 append res [$r get novar]
ed9b544e 93 } {11}
94
95 test {INCR against key created by incr itself} {
43c9dc7b 96 $r incr novar
ed9b544e 97 } {2}
98
99 test {INCR against key originally set with SET} {
43c9dc7b 100 $r set novar 100
101 $r incr novar
ed9b544e 102 } {101}
103
d68ed120 104 test {INCR over 32bit value} {
105 $r set novar 17179869184
106 $r incr novar
107 } {17179869185}
108
109 test {INCRBY over 32bit value with over 32bit increment} {
110 $r set novar 17179869184
111 $r incrby novar 17179869184
112 } {34359738368}
113
114 test {DECRBY over 32bit value with over 32bit increment, negative res} {
115 $r set novar 17179869184
116 $r decrby novar 17179869185
117 } {-1}
118
ed9b544e 119 test {SETNX target key missing} {
43c9dc7b 120 $r setnx novar2 foobared
121 $r get novar2
ed9b544e 122 } {foobared}
123
124 test {SETNX target key exists} {
43c9dc7b 125 $r setnx novar2 blabla
126 $r get novar2
ed9b544e 127 } {foobared}
128
129 test {EXISTS} {
130 set res {}
43c9dc7b 131 $r set newkey test
132 append res [$r exists newkey]
133 $r del newkey
134 append res [$r exists newkey]
ed9b544e 135 } {10}
136
137 test {Zero length value in key. SET/GET/EXISTS} {
43c9dc7b 138 $r set emptykey {}
139 set res [$r get emptykey]
140 append res [$r exists emptykey]
141 $r del emptykey
142 append res [$r exists emptykey]
ed9b544e 143 } {10}
144
145 test {Commands pipelining} {
43c9dc7b 146 set fd [$r channel]
ed9b544e 147 puts -nonewline $fd "SET k1 4\r\nxyzk\r\nGET k1\r\nPING\r\n"
148 flush $fd
149 set res {}
43c9dc7b 150 append res [string match OK* [::redis::redis_read_reply $fd]]
151 append res [::redis::redis_read_reply $fd]
152 append res [string match PONG* [::redis::redis_read_reply $fd]]
ed9b544e 153 format $res
154 } {1xyzk1}
155
156 test {Non existing command} {
43c9dc7b 157 catch {$r foobaredcommand} err
158 string match ERR* $err
ed9b544e 159 } {1}
160
161 test {Basic LPUSH, RPUSH, LLENGTH, LINDEX} {
43c9dc7b 162 $r lpush mylist a
163 $r lpush mylist b
164 $r rpush mylist c
165 set res [$r llen mylist]
166 append res [$r lindex mylist 0]
167 append res [$r lindex mylist 1]
168 append res [$r lindex mylist 2]
ed9b544e 169 } {3bac}
170
171 test {DEL a list} {
43c9dc7b 172 $r del mylist
173 $r exists mylist
ed9b544e 174 } {0}
175
176 test {Create a long list and check every single element with LINDEX} {
177 set ok 0
178 for {set i 0} {$i < 1000} {incr i} {
43c9dc7b 179 $r rpush mylist $i
ed9b544e 180 }
181 for {set i 0} {$i < 1000} {incr i} {
43c9dc7b 182 if {[$r lindex mylist $i] eq $i} {incr ok}
183 if {[$r lindex mylist [expr (-$i)-1]] eq [expr 999-$i]} {
ed9b544e 184 incr ok
185 }
186 }
187 format $ok
188 } {2000}
189
190 test {Test elements with LINDEX in random access} {
191 set ok 0
192 for {set i 0} {$i < 1000} {incr i} {
43c9dc7b 193 set rint [expr int(rand()*1000)]
194 if {[$r lindex mylist $rint] eq $rint} {incr ok}
195 if {[$r lindex mylist [expr (-$rint)-1]] eq [expr 999-$rint]} {
ed9b544e 196 incr ok
197 }
198 }
199 format $ok
200 } {2000}
201
202 test {LLEN against non-list value error} {
43c9dc7b 203 $r del mylist
204 $r set mylist foobar
205 catch {$r llen mylist} err
206 format $err
c937aa89 207 } {ERR*}
ed9b544e 208
209 test {LINDEX against non-list value error} {
43c9dc7b 210 catch {$r lindex mylist 0} err
211 format $err
c937aa89 212 } {ERR*}
ed9b544e 213
214 test {LPUSH against non-list value error} {
43c9dc7b 215 catch {$r lpush mylist 0} err
216 format $err
c937aa89 217 } {ERR*}
ed9b544e 218
219 test {RPUSH against non-list value error} {
43c9dc7b 220 catch {$r rpush mylist 0} err
221 format $err
c937aa89 222 } {ERR*}
ed9b544e 223
224 test {RENAME basic usage} {
43c9dc7b 225 $r set mykey hello
226 $r rename mykey mykey1
227 $r rename mykey1 mykey2
228 $r get mykey2
ed9b544e 229 } {hello}
230
231 test {RENAME source key should no longer exist} {
43c9dc7b 232 $r exists mykey
ed9b544e 233 } {0}
234
235 test {RENAME against already existing key} {
43c9dc7b 236 $r set mykey a
237 $r set mykey2 b
238 $r rename mykey2 mykey
239 set res [$r get mykey]
240 append res [$r exists mykey2]
ed9b544e 241 } {b0}
242
243 test {RENAMENX basic usage} {
43c9dc7b 244 $r del mykey
245 $r del mykey2
246 $r set mykey foobar
247 $r renamenx mykey mykey2
248 set res [$r get mykey2]
249 append res [$r exists mykey]
ed9b544e 250 } {foobar0}
251
252 test {RENAMENX against already existing key} {
43c9dc7b 253 $r set mykey foo
254 $r set mykey2 bar
255 $r renamenx mykey mykey2
ed9b544e 256 } {0}
257
258 test {RENAMENX against already existing key (2)} {
43c9dc7b 259 set res [$r get mykey]
260 append res [$r get mykey2]
ed9b544e 261 } {foobar}
262
263 test {RENAME against non existing source key} {
43c9dc7b 264 catch {$r rename nokey foobar} err
265 format $err
c937aa89 266 } {ERR*}
ed9b544e 267
268 test {RENAME where source and dest key is the same} {
43c9dc7b 269 catch {$r rename mykey mykey} err
270 format $err
c937aa89 271 } {ERR*}
ed9b544e 272
273 test {DEL all keys again (DB 0)} {
43c9dc7b 274 foreach key [$r keys *] {
275 $r del $key
ed9b544e 276 }
43c9dc7b 277 $r dbsize
ed9b544e 278 } {0}
279
280 test {DEL all keys again (DB 1)} {
43c9dc7b 281 $r select 1
282 foreach key [$r keys *] {
283 $r del $key
ed9b544e 284 }
43c9dc7b 285 set res [$r dbsize]
286 $r select 0
ed9b544e 287 format $res
288 } {0}
289
290 test {MOVE basic usage} {
43c9dc7b 291 $r set mykey foobar
292 $r move mykey 1
ed9b544e 293 set res {}
43c9dc7b 294 lappend res [$r exists mykey]
295 lappend res [$r dbsize]
296 $r select 1
297 lappend res [$r get mykey]
298 lappend res [$r dbsize]
299 $r select 0
ed9b544e 300 format $res
301 } [list 0 0 foobar 1]
302
303 test {MOVE against key existing in the target DB} {
43c9dc7b 304 $r set mykey hello
305 $r move mykey 1
ed9b544e 306 } {0}
307
308 test {SET/GET keys in different DBs} {
43c9dc7b 309 $r set a hello
310 $r set b world
311 $r select 1
312 $r set a foo
313 $r set b bared
314 $r select 0
ed9b544e 315 set res {}
43c9dc7b 316 lappend res [$r get a]
317 lappend res [$r get b]
318 $r select 1
319 lappend res [$r get a]
320 lappend res [$r get b]
321 $r select 0
ed9b544e 322 format $res
323 } {hello world foo bared}
324
325 test {Basic LPOP/RPOP} {
43c9dc7b 326 $r del mylist
327 $r rpush mylist 1
328 $r rpush mylist 2
329 $r lpush mylist 0
330 list [$r lpop mylist] [$r rpop mylist] [$r lpop mylist] [$r llen mylist]
ed9b544e 331 } [list 0 2 1 0]
332
333 test {LPOP/RPOP against empty list} {
43c9dc7b 334 $r lpop mylist
ed9b544e 335 } {}
336
337 test {LPOP against non list value} {
43c9dc7b 338 $r set notalist foo
339 catch {$r lpop notalist} err
340 format $err
c937aa89 341 } {ERR*kind*}
ed9b544e 342
343 test {Mass LPUSH/LPOP} {
344 set sum 0
345 for {set i 0} {$i < 1000} {incr i} {
43c9dc7b 346 $r lpush mylist $i
ed9b544e 347 incr sum $i
348 }
349 set sum2 0
350 for {set i 0} {$i < 500} {incr i} {
43c9dc7b 351 incr sum2 [$r lpop mylist]
352 incr sum2 [$r rpop mylist]
ed9b544e 353 }
354 expr $sum == $sum2
355 } {1}
356
357 test {LRANGE basics} {
358 for {set i 0} {$i < 10} {incr i} {
43c9dc7b 359 $r rpush mylist $i
ed9b544e 360 }
43c9dc7b 361 list [$r lrange mylist 1 -2] \
362 [$r lrange mylist -3 -1] \
363 [$r lrange mylist 4 4]
ed9b544e 364 } {{1 2 3 4 5 6 7 8} {7 8 9} 4}
365
366 test {LRANGE inverted indexes} {
43c9dc7b 367 $r lrange mylist 6 2
ed9b544e 368 } {}
369
370 test {LRANGE out of range indexes including the full list} {
43c9dc7b 371 $r lrange mylist -1000 1000
ed9b544e 372 } {0 1 2 3 4 5 6 7 8 9}
373
374 test {LRANGE against non existing key} {
43c9dc7b 375 $r lrange nosuchkey 0 1
ed9b544e 376 } {}
377
378 test {LTRIM basics} {
43c9dc7b 379 $r del mylist
ed9b544e 380 for {set i 0} {$i < 100} {incr i} {
43c9dc7b 381 $r lpush mylist $i
382 $r ltrim mylist 0 4
ed9b544e 383 }
43c9dc7b 384 $r lrange mylist 0 -1
ed9b544e 385 } {99 98 97 96 95}
386
387 test {LSET} {
43c9dc7b 388 $r lset mylist 1 foo
389 $r lset mylist -1 bar
390 $r lrange mylist 0 -1
ed9b544e 391 } {99 foo 97 96 bar}
392
393 test {LSET out of range index} {
43c9dc7b 394 catch {$r lset mylist 10 foo} err
395 format $err
c937aa89 396 } {ERR*range*}
ed9b544e 397
398 test {LSET against non existing key} {
43c9dc7b 399 catch {$r lset nosuchkey 10 foo} err
400 format $err
c937aa89 401 } {ERR*key*}
ed9b544e 402
403 test {LSET against non list value} {
43c9dc7b 404 $r set nolist foobar
405 catch {$r lset nolist 0 foo} err
406 format $err
c937aa89 407 } {ERR*value*}
ed9b544e 408
409 test {SADD, SCARD, SISMEMBER, SMEMBERS basics} {
43c9dc7b 410 $r sadd myset foo
411 $r sadd myset bar
412 list [$r scard myset] [$r sismember myset foo] \
413 [$r sismember myset bar] [$r sismember myset bla] \
414 [lsort [$r smembers myset]]
ed9b544e 415 } {2 1 1 0 {bar foo}}
416
417 test {SADD adding the same element multiple times} {
43c9dc7b 418 $r sadd myset foo
419 $r sadd myset foo
420 $r sadd myset foo
421 $r scard myset
ed9b544e 422 } {2}
423
424 test {SADD against non set} {
43c9dc7b 425 catch {$r sadd mylist foo} err
426 format $err
c937aa89 427 } {ERR*kind*}
ed9b544e 428
429 test {SREM basics} {
43c9dc7b 430 $r sadd myset ciao
431 $r srem myset foo
432 lsort [$r smembers myset]
ed9b544e 433 } {bar ciao}
434
435 test {Mass SADD and SINTER with two sets} {
436 for {set i 0} {$i < 1000} {incr i} {
43c9dc7b 437 $r sadd set1 $i
438 $r sadd set2 [expr $i+995]
ed9b544e 439 }
43c9dc7b 440 lsort [$r sinter set1 set2]
ed9b544e 441 } {995 996 997 998 999}
40d224a9 442
443 test {SUNION with two sets} {
444 lsort [$r sunion set1 set2]
445 } [lsort -uniq "[$r smembers set1] [$r smembers set2]"]
ed9b544e 446
447 test {SINTERSTORE with two sets} {
43c9dc7b 448 $r sinterstore setres set1 set2
449 lsort [$r smembers setres]
ed9b544e 450 } {995 996 997 998 999}
451
40d224a9 452 test {SUNIONSTORE with two sets} {
453 $r sunionstore setres set1 set2
454 lsort [$r smembers setres]
455 } [lsort -uniq "[$r smembers set1] [$r smembers set2]"]
456
ed9b544e 457 test {SINTER against three sets} {
43c9dc7b 458 $r sadd set3 999
459 $r sadd set3 995
460 $r sadd set3 1000
461 $r sadd set3 2000
462 lsort [$r sinter set1 set2 set3]
ed9b544e 463 } {995 999}
464
465 test {SINTERSTORE with three sets} {
43c9dc7b 466 $r sinterstore setres set1 set2 set3
467 lsort [$r smembers setres]
ed9b544e 468 } {995 999}
40d224a9 469
470 test {SUNION with non existing keys} {
471 lsort [$r sunion nokey1 set1 set2 nokey2]
472 } [lsort -uniq "[$r smembers set1] [$r smembers set2]"]
473
ed9b544e 474 test {SAVE - make sure there are all the types as values} {
43c9dc7b 475 $r lpush mysavelist hello
476 $r lpush mysavelist world
477 $r set myemptykey {}
478 $r set mynormalkey {blablablba}
479 $r save
c937aa89 480 } {OK}
ed9b544e 481
482 test {Create a random list} {
483 set tosort {}
484 array set seenrand {}
485 for {set i 0} {$i < 10000} {incr i} {
486 while 1 {
487 # Make sure all the weights are different because
488 # Redis does not use a stable sort but Tcl does.
43c9dc7b 489 set rint [expr int(rand()*1000000)]
490 if {![info exists seenrand($rint)]} break
ed9b544e 491 }
43c9dc7b 492 set seenrand($rint) x
493 $r lpush tosort $i
494 $r set weight_$i $rint
495 lappend tosort [list $i $rint]
ed9b544e 496 }
497 set sorted [lsort -index 1 -real $tosort]
498 set res {}
499 for {set i 0} {$i < 10000} {incr i} {
500 lappend res [lindex $sorted $i 0]
501 }
502 format {}
503 } {}
504
505 test {SORT with BY against the newly created list} {
43c9dc7b 506 $r sort tosort {BY weight_*}
ed9b544e 507 } $res
508
509 test {SORT direct, numeric, against the newly created list} {
43c9dc7b 510 $r sort tosort
ed9b544e 511 } [lsort -integer $res]
512
513 test {SORT decreasing sort} {
43c9dc7b 514 $r sort tosort {DESC}
ed9b544e 515 } [lsort -decreasing -integer $res]
516
517 test {SORT speed, sorting 10000 elements list using BY, 100 times} {
518 set start [clock clicks -milliseconds]
519 for {set i 0} {$i < 100} {incr i} {
43c9dc7b 520 set sorted [$r sort tosort {BY weight_* LIMIT 0 10}]
ed9b544e 521 }
522 set elapsed [expr [clock clicks -milliseconds]-$start]
523 puts -nonewline "\n Average time to sort: [expr double($elapsed)/100] milliseconds "
524 flush stdout
525 format {}
526 } {}
527
528 test {SORT speed, sorting 10000 elements list directly, 100 times} {
529 set start [clock clicks -milliseconds]
530 for {set i 0} {$i < 100} {incr i} {
43c9dc7b 531 set sorted [$r sort tosort {LIMIT 0 10}]
ed9b544e 532 }
533 set elapsed [expr [clock clicks -milliseconds]-$start]
534 puts -nonewline "\n Average time to sort: [expr double($elapsed)/100] milliseconds "
535 flush stdout
536 format {}
537 } {}
538
539 test {SORT speed, pseudo-sorting 10000 elements list, BY <const>, 100 times} {
540 set start [clock clicks -milliseconds]
541 for {set i 0} {$i < 100} {incr i} {
43c9dc7b 542 set sorted [$r sort tosort {BY nokey LIMIT 0 10}]
ed9b544e 543 }
544 set elapsed [expr [clock clicks -milliseconds]-$start]
545 puts -nonewline "\n Average time to sort: [expr double($elapsed)/100] milliseconds "
546 flush stdout
547 format {}
548 } {}
549
550 test {SORT regression for issue #19, sorting floats} {
43c9dc7b 551 $r flushdb
ed9b544e 552 foreach x {1.1 5.10 3.10 7.44 2.1 5.75 6.12 0.25 1.15} {
43c9dc7b 553 $r lpush mylist $x
ed9b544e 554 }
43c9dc7b 555 $r sort mylist
ed9b544e 556 } [lsort -real {1.1 5.10 3.10 7.44 2.1 5.75 6.12 0.25 1.15}]
557
558 test {LREM, remove all the occurrences} {
43c9dc7b 559 $r flushall
560 $r rpush mylist foo
561 $r rpush mylist bar
562 $r rpush mylist foobar
563 $r rpush mylist foobared
564 $r rpush mylist zap
565 $r rpush mylist bar
566 $r rpush mylist test
567 $r rpush mylist foo
568 set res [$r lrem mylist 0 bar]
569 list [$r lrange mylist 0 -1] $res
ed9b544e 570 } {{foo foobar foobared zap test foo} 2}
571
572 test {LREM, remove the first occurrence} {
43c9dc7b 573 set res [$r lrem mylist 1 foo]
574 list [$r lrange mylist 0 -1] $res
ed9b544e 575 } {{foobar foobared zap test foo} 1}
576
577 test {LREM, remove non existing element} {
43c9dc7b 578 set res [$r lrem mylist 1 nosuchelement]
579 list [$r lrange mylist 0 -1] $res
ed9b544e 580 } {{foobar foobared zap test foo} 0}
581
582 test {LREM, starting from tail with negative count} {
43c9dc7b 583 $r flushall
584 $r rpush mylist foo
585 $r rpush mylist bar
586 $r rpush mylist foobar
587 $r rpush mylist foobared
588 $r rpush mylist zap
589 $r rpush mylist bar
590 $r rpush mylist test
591 $r rpush mylist foo
592 $r rpush mylist foo
593 set res [$r lrem mylist -1 bar]
594 list [$r lrange mylist 0 -1] $res
ed9b544e 595 } {{foo bar foobar foobared zap test foo foo} 1}
596
597 test {LREM, starting from tail with negative count (2)} {
43c9dc7b 598 set res [$r lrem mylist -2 foo]
599 list [$r lrange mylist 0 -1] $res
ed9b544e 600 } {{foo bar foobar foobared zap test} 2}
601
5b19bd72 602 test {MGET} {
43c9dc7b 603 $r flushall
604 $r set foo BAR
605 $r set bar FOO
606 $r mget foo bar
5b19bd72 607 } {BAR FOO}
608
609 test {MGET against non existing key} {
43c9dc7b 610 $r mget foo baazz bar
5b19bd72 611 } {BAR {} FOO}
612
613 test {MGET against non-string key} {
43c9dc7b 614 $r sadd myset ciao
615 $r sadd myset bau
616 $r mget foo baazz bar myset
5b19bd72 617 } {BAR {} FOO {}}
618
ce7bef07 619 test {RANDOMKEY} {
620 $r flushall
621 $r set foo x
622 $r set bar y
623 set foo_seen 0
624 set bar_seen 0
625 for {set i 0} {$i < 100} {incr i} {
626 set rkey [$r randomkey]
627 if {$rkey eq {foo}} {
628 set foo_seen 1
629 }
630 if {$rkey eq {bar}} {
631 set bar_seen 1
632 }
633 }
634 list $foo_seen $bar_seen
635 } {1 1}
636
637 test {RANDOMKEY against empty DB} {
638 $r flushall
639 $r randomkey
640 } {}
641
f5785ae9 642 test {RANDOMKEY regression 1} {
643 $r flushall
644 $r set x 10
645 $r del x
646 $r randomkey
647 } {}
648
7ac6d461 649 test {GETSET (set new value)} {
650 list [$r getset foo xyz] [$r get foo]
651 } {{} xyz}
652
653 test {GETSET (replace old value)} {
654 $r set foo bar
655 list [$r getset foo xyz] [$r get foo]
656 } {bar xyz}
657
ed9b544e 658 # Leave the user with a clean DB before to exit
659 test {FLUSHALL} {
43c9dc7b 660 $r flushall
661 $r dbsize
ed9b544e 662 } {0}
663
664 puts "\n[expr $::passed+$::failed] tests, $::passed passed, $::failed failed"
665 if {$::failed > 0} {
666 puts "\n*** WARNING!!! $::failed FAILED TESTS ***\n"
667 }
668 close $fd
669}
670
5a6948fb 671proc stress {} {
43c9dc7b 672 set r [redis]
673 $r flushall
5a6948fb 674 while 1 {
675 set randkey [expr int(rand()*10000)]
676 set randval [expr int(rand()*10000)]
677 set randidx0 [expr int(rand()*10)]
678 set randidx1 [expr int(rand()*10)]
679 set cmd [expr int(rand()*10)]
43c9dc7b 680 catch {
681 if {$cmd == 0} {$r set $randkey $randval}
682 if {$cmd == 1} {$r get $randkey}
683 if {$cmd == 2} {$r incr $randkey}
684 if {$cmd == 3} {$r lpush $randkey $randval}
685 if {$cmd == 4} {$r rpop $randkey}
686 if {$cmd == 5} {$r del $randkey}
687 if {$cmd == 6} {$r lrange $randkey $randidx0 $randidx1}
688 if {$cmd == 7} {$r ltrim $randkey $randidx0 $randidx1}
689 if {$cmd == 8} {$r lindex $randkey $randidx0}
690 if {$cmd == 9} {$r lset $randkey $randidx0 $randval}
691 }
5a6948fb 692 flush stdout
693 }
43c9dc7b 694 $r close
5a6948fb 695}
696
ed9b544e 697if {[llength $argv] == 0} {
698 main 127.0.0.1 6379
5a6948fb 699} elseif {[llength $argv] == 1 && [lindex $argv 0] eq {stress}} {
700 stress
ed9b544e 701} else {
702 main [lindex $argv 0] [lindex $argv 1]
703}