2 # Redis test suite. Copyright (C) 2009 Salvatore Sanfilippo antirez@gmail.com
3 # This softare is released under the BSD License. See the COPYING file for
13 proc test
{name code okpattern
} {
15 if {$::testnum < $::first ||
$::testnum > $::last} return
16 puts -nonewline [format "%-70s " "#$::testnum $name"]
18 set retval
[uplevel 1 $code]
19 if {$okpattern eq
$retval ||
[string match
$okpattern $retval]} {
23 puts "!! ERROR expected\n'$okpattern'\nbut got\n'$retval'"
28 proc randstring
{min max
{type
binary}} {
29 set len
[expr {$min+int
(rand
()*($max-$min+1))}]
31 if {$type eq
{binary}} {
34 } elseif
{$type eq
{alpha
}} {
37 } elseif
{$type eq
{compr
}} {
42 append output
[format "%c" [expr {$minval+int
(rand
()*($maxval-$minval+1))}]]
48 # Useful for some test
49 proc zlistAlikeSort
{a b
} {
50 if {[lindex $a 0] > [lindex $b 0]} {return 1}
51 if {[lindex $a 0] < [lindex $b 0]} {return -1}
52 string compare
[lindex $a 1] [lindex $b 1]
55 proc waitForBgsave r
{
58 if {[string match
{*bgsave_in_progress
:1*} $i]} {
59 puts -nonewline "\nWaiting for background save to finish... "
68 proc waitForBgrewriteaof r
{
71 if {[string match
{*bgrewriteaof_in_progress
:1*} $i]} {
72 puts -nonewline "\nWaiting for background AOF rewrite to finish... "
81 proc randomInt
{max
} {
82 expr {int
(rand
()*$max)}
86 set path
[expr {int
(rand
()*[llength $args])}]
87 uplevel 1 [lindex $args $path]
92 # Small enough to likely collide
95 # 32 bit compressible signed/unsigned
96 randpath
{randomInt
2000000000} {randomInt
4000000000}
99 randpath
{randomInt
1000000000000}
102 randpath
{randstring
0 256 alpha
} \
103 {randstring
0 256 compr
} \
104 {randstring
0 256 binary}
110 # Small enough to likely collide
113 # 32 bit compressible signed/unsigned
114 randpath
{randomInt
2000000000} {randomInt
4000000000}
117 randpath
{randomInt
1000000000000}
120 randpath
{randstring
1 256 alpha
} \
121 {randstring
1 256 compr
}
125 proc createComplexDataset
{r ops
} {
126 for {set j
0} {$j < $ops} {incr j
} {
131 set d
[expr {rand
()}]
133 set d
[expr {rand
()}]
135 set d
[expr {rand
()}]
137 set d
[expr {rand
()}]
139 set d
[expr {rand
()}]
141 randpath
{set d
+inf
} {set d
-inf}
165 randpath
{$r lpush
$k $v} \
172 randpath
{$r sadd
$k $v} \
176 randpath
{$r zadd
$k $d $v} \
180 randpath
{$r hset
$k $f $v} \
187 proc datasetDigest r
{
188 set keys
[lsort [$r keys
*]]
194 set aux
[::sha1::sha1 -hex [$r get
$k]]
196 if {[$r llen
$k] == 0} {
199 set aux
[::sha1::sha1 -hex [$r lrange $k 0 -1]]
202 if {[$r scard
$k] == 0} {
205 set aux
[::sha1::sha1 -hex [lsort [$r smembers
$k]]]
208 if {[$r zcard
$k] == 0} {
211 set aux
[::sha1::sha1 -hex [$r zrange
$k 0 -1]]
214 if {[$r hlen
$k] == 0} {
217 set aux
[::sha1::sha1 -hex [lsort [$r hgetall
$k]]]
220 error "Type not supported: $t"
223 if {$aux eq
{}} continue
224 set digest
[::sha1::sha1 -hex [join [list $aux $digest $k] "\n"]]
229 proc main
{server port
} {
230 set r
[redis
$server $port]
235 # The following AUTH test should be enabled only when requirepass
236 # <PASSWORD> is set in redis.conf and redis-server was started with
237 # redis.conf as the first argument.
239 #test {AUTH with requirepass in redis.conf} {
243 test
{DEL all keys to start with a clean DB
} {
244 foreach key
[$r keys
*] {$r del
$key}
248 test
{SET and GET an item
} {
253 test
{SET and GET an empty item
} {
258 test
{DEL against a single item
} {
267 list [$r del foo1 foo2 foo3 foo4
] [$r mget foo1 foo2 foo3
]
270 test
{KEYS with pattern
} {
271 foreach key
{key_x key_y key_z foo_a foo_b foo_c
} {
275 } {foo_a foo_b foo_c
}
277 test
{KEYS to get all keys
} {
279 } {foo_a foo_b foo_c key_x key_y key_z
}
285 test
{DEL all keys
} {
286 foreach key
[$r keys
*] {$r del
$key}
290 test
{Very big payload in GET
/SET
} {
291 set buf
[string repeat
"abcd" 1000000]
294 } [string repeat
"abcd" 1000000]
296 test
{Very big payload random access
} {
299 for {set j
0} {$j < 100} {incr j
} {
300 set size
[expr 1+[randomInt
100000]]
301 set buf
[string repeat
"pl-$j" $size]
303 $r set bigpayload_
$j $buf
305 for {set j
0} {$j < 1000} {incr j
} {
306 set index
[randomInt
100]
307 set buf
[$r get bigpayload_
$index]
308 if {$buf != $payload($index)} {
309 set err
"Values differ: I set '$payload($index)' but I read back '$buf'"
317 test
{SET
10000 numeric keys and access all them in reverse order
} {
319 for {set x
0} {$x < 10000} {incr x
} {
323 for {set x
9999} {$x >= 0} {incr x
-1} {
326 set err
"Eleemnt at position $x is $val instead of $x"
333 test
{DBSIZE should be
10101 now
} {
337 test
{INCR against non existing key
} {
339 append res
[$r incr novar
]
340 append res
[$r get novar
]
343 test
{INCR against key created by
incr itself
} {
347 test
{INCR against key originally
set with SET
} {
352 test
{INCR over
32bit value
} {
353 $r set novar
17179869184
357 test
{INCRBY over
32bit value with over
32bit increment
} {
358 $r set novar
17179869184
359 $r incrby novar
17179869184
362 test
{INCR fails against key with spaces
(no integer encoded
)} {
364 catch {$r incr novar
} err
368 test
{INCR fails against a key holding a
list} {
370 catch {$r incr novar
} err
375 test
{DECRBY over
32bit value with over
32bit increment
, negative res
} {
376 $r set novar
17179869184
377 $r decrby novar
17179869185
380 test
{SETNX target key missing
} {
381 $r setnx novar2 foobared
385 test
{SETNX target key exists
} {
386 $r setnx novar2 blabla
390 test
{SETNX will overwrite EXPIREing key
} {
400 append res
[$r exists newkey
]
402 append res
[$r exists newkey
]
405 test
{Zero length value in key. SET
/GET
/EXISTS
} {
407 set res
[$r get emptykey
]
408 append res
[$r exists emptykey
]
410 append res
[$r exists emptykey
]
413 test
{Commands pipelining
} {
415 puts -nonewline $fd "SET k1 4\r\nxyzk\r\nGET k1\r\nPING\r\n"
418 append res
[string match OK
* [::redis::redis_read_reply $fd]]
419 append res
[::redis::redis_read_reply $fd]
420 append res
[string match PONG
* [::redis::redis_read_reply $fd]]
424 test
{Non existing command
} {
425 catch {$r foobaredcommand
} err
426 string match ERR
* $err
429 test
{Basic LPUSH
, RPUSH
, LLENGTH
, LINDEX
} {
430 set res
[$r lpush mylist a
]
431 append res
[$r lpush mylist b
]
432 append res
[$r rpush mylist c
]
433 append res
[$r llen mylist
]
434 append res
[$r rpush anotherlist d
]
435 append res
[$r lpush anotherlist e
]
436 append res
[$r llen anotherlist
]
437 append res
[$r lindex mylist
0]
438 append res
[$r lindex mylist
1]
439 append res
[$r lindex mylist
2]
440 append res
[$r lindex anotherlist
0]
441 append res
[$r lindex anotherlist
1]
442 list $res [$r lindex mylist
100]
450 test
{Create a long
list and check every single element with LINDEX
} {
452 for {set i
0} {$i < 1000} {incr i
} {
455 for {set i
0} {$i < 1000} {incr i
} {
456 if {[$r lindex mylist
$i] eq
$i} {incr ok
}
457 if {[$r lindex mylist
[expr (-$i)-1]] eq
[expr 999-$i]} {
464 test
{Test elements with LINDEX in random access
} {
466 for {set i
0} {$i < 1000} {incr i
} {
467 set rint
[expr int
(rand
()*1000)]
468 if {[$r lindex mylist
$rint] eq
$rint} {incr ok
}
469 if {[$r lindex mylist
[expr (-$rint)-1]] eq
[expr 999-$rint]} {
476 test
{Check
if the
list is still ok
after a DEBUG RELOAD
} {
479 for {set i
0} {$i < 1000} {incr i
} {
480 set rint
[expr int
(rand
()*1000)]
481 if {[$r lindex mylist
$rint] eq
$rint} {incr ok
}
482 if {[$r lindex mylist
[expr (-$rint)-1]] eq
[expr 999-$rint]} {
489 test
{LLEN against non-list value
error} {
492 catch {$r llen mylist
} err
496 test
{LLEN against non existing key
} {
500 test
{LINDEX against non-list value
error} {
501 catch {$r lindex mylist
0} err
505 test
{LINDEX against non existing key
} {
506 $r lindex not-a-key
10
509 test
{LPUSH against non-list value
error} {
510 catch {$r lpush mylist
0} err
514 test
{RPUSH against non-list value
error} {
515 catch {$r rpush mylist
0} err
519 test
{RPOPLPUSH base case
} {
525 set v1
[$r rpoplpush mylist newlist
]
526 set v2
[$r rpoplpush mylist newlist
]
527 set l1
[$r lrange mylist
0 -1]
528 set l2
[$r lrange newlist
0 -1]
532 test
{RPOPLPUSH with the same
list as src and dst
} {
537 set l1
[$r lrange mylist
0 -1]
538 set v
[$r rpoplpush mylist mylist
]
539 set l2
[$r lrange mylist
0 -1]
541 } {{a b c
} c
{c a b
}}
543 test
{RPOPLPUSH target
list already exists
} {
551 set v1
[$r rpoplpush mylist newlist
]
552 set v2
[$r rpoplpush mylist newlist
]
553 set l1
[$r lrange mylist
0 -1]
554 set l2
[$r lrange newlist
0 -1]
556 } {d c
{a b
} {c d x
}}
558 test
{RPOPLPUSH against non existing key
} {
561 set v1
[$r rpoplpush mylist newlist
]
562 list $v1 [$r exists mylist
] [$r exists newlist
]
565 test
{RPOPLPUSH against non
list src key
} {
569 catch {$r rpoplpush mylist newlist
} err
570 list [$r type mylist
] [$r exists newlist
] [string range
$err 0 2]
573 test
{RPOPLPUSH against non
list dst key
} {
581 catch {$r rpoplpush mylist newlist
} err
582 list [$r lrange mylist
0 -1] [$r type newlist
] [string range
$err 0 2]
583 } {{a b c d
} string ERR
}
585 test
{RPOPLPUSH against non existing src key
} {
588 $r rpoplpush mylist newlist
591 test
{RENAME basic usage
} {
593 $r rename mykey mykey1
594 $r rename mykey1 mykey2
598 test
{RENAME
source key should no longer exist
} {
602 test
{RENAME against already existing key
} {
605 $r rename mykey2 mykey
606 set res
[$r get mykey
]
607 append res
[$r exists mykey2
]
610 test
{RENAMENX basic usage
} {
614 $r renamenx mykey mykey2
615 set res
[$r get mykey2
]
616 append res
[$r exists mykey
]
619 test
{RENAMENX against already existing key
} {
622 $r renamenx mykey mykey2
625 test
{RENAMENX against already existing key
(2)} {
626 set res
[$r get mykey
]
627 append res
[$r get mykey2
]
630 test
{RENAME against non existing
source key
} {
631 catch {$r rename nokey foobar
} err
635 test
{RENAME where
source and dest key is the same
} {
636 catch {$r rename mykey mykey
} err
640 test
{DEL all keys again
(DB
0)} {
641 foreach key
[$r keys
*] {
647 test
{DEL all keys again
(DB
1)} {
649 foreach key
[$r keys
*] {
657 test
{MOVE basic usage
} {
661 lappend res
[$r exists mykey
]
662 lappend res
[$r dbsize
]
664 lappend res
[$r get mykey
]
665 lappend res
[$r dbsize
]
668 } [list 0 0 foobar
1]
670 test
{MOVE against key existing in the target DB
} {
675 test
{SET
/GET keys in different DBs
} {
683 lappend res
[$r get a
]
684 lappend res
[$r get b
]
686 lappend res
[$r get a
]
687 lappend res
[$r get b
]
690 } {hello world foo bared
}
692 test
{Basic LPOP
/RPOP
} {
697 list [$r lpop mylist
] [$r rpop mylist
] [$r lpop mylist
] [$r llen mylist
]
700 test
{LPOP
/RPOP against empty
list} {
704 test
{LPOP against non
list value
} {
706 catch {$r lpop notalist
} err
710 test
{Mass LPUSH
/LPOP
} {
712 for {set i
0} {$i < 1000} {incr i
} {
717 for {set i
0} {$i < 500} {incr i
} {
718 incr sum2
[$r lpop mylist
]
719 incr sum2
[$r rpop mylist
]
724 test
{LRANGE basics
} {
725 for {set i
0} {$i < 10} {incr i
} {
728 list [$r lrange mylist
1 -2] \
729 [$r lrange mylist
-3 -1] \
730 [$r lrange mylist
4 4]
731 } {{1 2 3 4 5 6 7 8} {7 8 9} 4}
733 test
{LRANGE inverted indexes
} {
737 test
{LRANGE out of range indexes including the full
list} {
738 $r lrange mylist
-1000 1000
739 } {0 1 2 3 4 5 6 7 8 9}
741 test
{LRANGE against non existing key
} {
742 $r lrange nosuchkey
0 1
745 test
{LTRIM basics
} {
747 for {set i
0} {$i < 100} {incr i
} {
751 $r lrange mylist
0 -1
754 test
{LTRIM stress testing
} {
757 for {set i
0} {$i < 20} {incr i
} {
761 for {set j
0} {$j < 100} {incr j
} {
764 for {set i
0} {$i < 20} {incr i
} {
770 $r ltrim mylist
$a $b
771 if {[$r lrange mylist
0 -1] ne
[lrange $mylist $a $b]} {
772 set err
"[$r lrange mylist 0 -1] != [lrange $mylist $a $b]"
781 foreach x
{99 98 97 96 95} {
785 $r lset mylist
-1 bar
786 $r lrange mylist
0 -1
789 test
{LSET out of range index
} {
790 catch {$r lset mylist
10 foo
} err
794 test
{LSET against non existing key
} {
795 catch {$r lset nosuchkey
10 foo
} err
799 test
{LSET against non
list value
} {
801 catch {$r lset nolist
0 foo
} err
805 test
{SADD
, SCARD
, SISMEMBER
, SMEMBERS basics
} {
808 list [$r scard myset
] [$r sismember myset foo
] \
809 [$r sismember myset bar
] [$r sismember myset bla
] \
810 [lsort [$r smembers myset
]]
811 } {2 1 1 0 {bar foo
}}
813 test
{SADD adding the same element multiple times
} {
820 test
{SADD against non
set} {
821 catch {$r sadd mylist foo
} err
828 lsort [$r smembers myset
]
831 test
{Mass SADD and SINTER with two sets
} {
832 for {set i
0} {$i < 1000} {incr i
} {
834 $r sadd set2
[expr $i+995]
836 lsort [$r sinter set1 set2
]
837 } {995 996 997 998 999}
839 test
{SUNION with two sets
} {
840 lsort [$r sunion set1 set2
]
841 } [lsort -uniq "[$r smembers set1] [$r smembers set2]"]
843 test
{SINTERSTORE with two sets
} {
844 $r sinterstore setres set1 set2
845 lsort [$r smembers setres
]
846 } {995 996 997 998 999}
848 test
{SINTERSTORE with two sets
, after a DEBUG RELOAD
} {
850 $r sinterstore setres set1 set2
851 lsort [$r smembers setres
]
852 } {995 996 997 998 999}
854 test
{SUNIONSTORE with two sets
} {
855 $r sunionstore setres set1 set2
856 lsort [$r smembers setres
]
857 } [lsort -uniq "[$r smembers set1] [$r smembers set2]"]
859 test
{SUNIONSTORE against non existing keys
} {
861 list [$r sunionstore setres foo111 bar222
] [$r exists xxx
]
864 test
{SINTER against three sets
} {
869 lsort [$r sinter set1 set2 set3
]
872 test
{SINTERSTORE with three sets
} {
873 $r sinterstore setres set1 set2 set3
874 lsort [$r smembers setres
]
877 test
{SUNION with non existing keys
} {
878 lsort [$r sunion nokey1 set1 set2 nokey2
]
879 } [lsort -uniq "[$r smembers set1] [$r smembers set2]"]
881 test
{SDIFF with two sets
} {
882 for {set i
5} {$i < 1000} {incr i
} {
885 lsort [$r sdiff set1 set4
]
888 test
{SDIFF with three sets
} {
890 lsort [$r sdiff set1 set4 set5
]
893 test
{SDIFFSTORE with three sets
} {
894 $r sdiffstore sres set1 set4 set5
895 lsort [$r smembers sres
]
903 list [lsort [list [$r spop myset
] [$r spop myset
] [$r spop myset
]]] [$r scard myset
]
906 test
{SAVE
- make sure there are all the types as values
} {
907 # Wait for a background saving in progress to terminate
909 $r lpush mysavelist hello
910 $r lpush mysavelist world
912 $r set mynormalkey
{blablablba
}
913 $r zadd mytestzset
10 a
914 $r zadd mytestzset
20 b
915 $r zadd mytestzset
30 c
924 unset -nocomplain myset
926 for {set i
0} {$i < 100} {incr i
} {
927 set myset
([$r srandmember myset
]) 1
929 lsort [array names myset
]
932 test
{Create a random
list and a random
set} {
934 array set seenrand
{}
935 for {set i
0} {$i < 10000} {incr i
} {
937 # Make sure all the weights are different because
938 # Redis does not use a stable sort but Tcl does.
940 set rint
[expr int
(rand
()*1000000)]
942 set rint
[expr rand
()]
944 if {![info exists seenrand
($rint)]} break
946 set seenrand
($rint) x
948 $r sadd tosort-set
$i
949 $r set weight_
$i $rint
950 lappend tosort
[list $i $rint]
952 set sorted
[lsort -index 1 -real $tosort]
954 for {set i
0} {$i < 10000} {incr i
} {
955 lappend res
[lindex $sorted $i 0]
960 test
{SORT with BY against the newly created
list} {
961 $r sort tosort
{BY weight_
*}
964 test
{the same SORT with BY
, but against the newly created
set} {
965 $r sort tosort-set
{BY weight_
*}
968 test
{SORT with BY and STORE against the newly created
list} {
969 $r sort tosort
{BY weight_
*} store sort-res
970 $r lrange sort-res
0 -1
973 test
{SORT direct
, numeric
, against the newly created
list} {
975 } [lsort -integer $res]
977 test
{SORT decreasing sort
} {
978 $r sort tosort
{DESC
}
979 } [lsort -decreasing -integer $res]
981 test
{SORT speed
, sorting
10000 elements
list using BY
, 100 times
} {
982 set start
[clock clicks
-milliseconds]
983 for {set i
0} {$i < 100} {incr i
} {
984 set sorted
[$r sort tosort
{BY weight_
* LIMIT
0 10}]
986 set elapsed
[expr [clock clicks
-milliseconds]-$start]
987 puts -nonewline "\n Average time to sort: [expr double($elapsed)/100] milliseconds "
992 test
{SORT speed
, sorting
10000 elements
list directly
, 100 times
} {
993 set start
[clock clicks
-milliseconds]
994 for {set i
0} {$i < 100} {incr i
} {
995 set sorted
[$r sort tosort
{LIMIT
0 10}]
997 set elapsed
[expr [clock clicks
-milliseconds]-$start]
998 puts -nonewline "\n Average time to sort: [expr double($elapsed)/100] milliseconds "
1003 test
{SORT speed
, pseudo-sorting
10000 elements
list, BY
<const
>, 100 times
} {
1004 set start
[clock clicks
-milliseconds]
1005 for {set i
0} {$i < 100} {incr i
} {
1006 set sorted
[$r sort tosort
{BY nokey LIMIT
0 10}]
1008 set elapsed
[expr [clock clicks
-milliseconds]-$start]
1009 puts -nonewline "\n Average time to sort: [expr double($elapsed)/100] milliseconds "
1014 test
{SORT regression
for issue
#19, sorting floats} {
1016 foreach x
{1.1 5.10 3.10 7.44 2.1 5.75 6.12 0.25 1.15} {
1020 } [lsort -real {1.1 5.10 3.10 7.44 2.1 5.75 6.12 0.25 1.15}]
1022 test
{SORT with GET
#} {
1027 $r mset weight_1
10 weight_2
5 weight_3
30
1028 $r sort mylist BY weight_
* GET
#
1031 test
{SORT with constant GET
} {
1032 $r sort mylist GET foo
1035 test
{LREM
, remove all the occurrences
} {
1039 $r rpush mylist foobar
1040 $r rpush mylist foobared
1043 $r rpush mylist test
1045 set res
[$r lrem mylist
0 bar
]
1046 list [$r lrange mylist
0 -1] $res
1047 } {{foo foobar foobared zap test foo
} 2}
1049 test
{LREM
, remove the first occurrence
} {
1050 set res
[$r lrem mylist
1 foo
]
1051 list [$r lrange mylist
0 -1] $res
1052 } {{foobar foobared zap test foo
} 1}
1054 test
{LREM
, remove non existing element
} {
1055 set res
[$r lrem mylist
1 nosuchelement
]
1056 list [$r lrange mylist
0 -1] $res
1057 } {{foobar foobared zap test foo
} 0}
1059 test
{LREM
, starting from tail with negative count
} {
1063 $r rpush mylist foobar
1064 $r rpush mylist foobared
1067 $r rpush mylist test
1070 set res
[$r lrem mylist
-1 bar
]
1071 list [$r lrange mylist
0 -1] $res
1072 } {{foo bar foobar foobared zap test foo foo
} 1}
1074 test
{LREM
, starting from tail with negative count
(2)} {
1075 set res
[$r lrem mylist
-2 foo
]
1076 list [$r lrange mylist
0 -1] $res
1077 } {{foo bar foobar foobared zap test
} 2}
1079 test
{LREM
, deleting objects that may be encoded as integers
} {
1080 $r lpush myotherlist
1
1081 $r lpush myotherlist
2
1082 $r lpush myotherlist
3
1083 $r lrem myotherlist
1 2
1094 test
{MGET against non existing key
} {
1095 $r mget foo baazz bar
1098 test
{MGET against non-string key
} {
1101 $r mget foo baazz bar myset
1110 for {set i
0} {$i < 100} {incr i
} {
1111 set rkey
[$r randomkey
]
1112 if {$rkey eq
{foo
}} {
1115 if {$rkey eq
{bar
}} {
1119 list $foo_seen $bar_seen
1122 test
{RANDOMKEY against empty DB
} {
1127 test
{RANDOMKEY regression
1} {
1134 test
{GETSET
(set new value
)} {
1135 list [$r getset foo xyz
] [$r get foo
]
1138 test
{GETSET
(replace old value
)} {
1140 list [$r getset foo xyz
] [$r get foo
]
1143 test
{SMOVE basics
} {
1150 $r smove myset1 myset2 a
1151 list [lsort [$r smembers myset2
]] [lsort [$r smembers myset1
]]
1154 test
{SMOVE non existing key
} {
1155 list [$r smove myset1 myset2 foo
] [lsort [$r smembers myset2
]] [lsort [$r smembers myset1
]]
1156 } {0 {a x y z
} {b c
}}
1158 test
{SMOVE non existing src
set} {
1159 list [$r smove noset myset2 foo
] [lsort [$r smembers myset2
]]
1162 test
{SMOVE non existing dst
set} {
1163 list [$r smove myset2 myset3 y
] [lsort [$r smembers myset2
]] [lsort [$r smembers myset3
]]
1166 test
{SMOVE wrong src key type
} {
1168 catch {$r smove x myset2 foo
} err
1172 test
{SMOVE wrong dst key type
} {
1174 catch {$r smove myset2 x foo
} err
1178 test
{MSET base case
} {
1179 $r mset x
10 y
"foo bar" z
"x x x x x x x\n\n\r\n"
1181 } [list 10 {foo bar
} "x x x x x x x\n\n\r\n"]
1183 test
{MSET wrong number of args
} {
1184 catch {$r mset x
10 y
"foo bar" z
} err
1188 test
{MSETNX with already existent key
} {
1189 list [$r msetnx x1 xxx y2 yyy x
20] [$r exists x1
] [$r exists y2
]
1192 test
{MSETNX with not existing keys
} {
1193 list [$r msetnx x1 xxx y2 yyy
] [$r get x1
] [$r get y2
]
1196 test
{MSETNX should remove all the volatile keys even on
failure} {
1200 list [$r msetnx x A y B z C
] [$r mget x y z
]
1203 test
{ZSET basic ZADD and score
update} {
1207 set aux1
[$r zrange ztmp
0 -1]
1209 set aux2
[$r zrange ztmp
0 -1]
1213 test
{ZCARD basics
} {
1217 test
{ZCARD non existing key
} {
1218 $r zcard ztmp-blabla
1221 test
{ZRANK basics
} {
1222 $r zadd zranktmp
10 x
1223 $r zadd zranktmp
20 y
1224 $r zadd zranktmp
30 z
1225 list [$r zrank zranktmp x
] [$r zrank zranktmp y
] [$r zrank zranktmp z
]
1228 test
{ZREVRANK basics
} {
1229 list [$r zrevrank zranktmp x
] [$r zrevrank zranktmp y
] [$r zrevrank zranktmp z
]
1232 test
{ZRANK
- after deletion
} {
1234 list [$r zrank zranktmp x
] [$r zrank zranktmp z
]
1240 for {set i
0} {$i < 1000} {incr i
} {
1241 set score
[expr rand
()]
1243 $r zadd zscoretest
$score $i
1245 for {set i
0} {$i < 1000} {incr i
} {
1246 if {[$r zscore zscoretest
$i] != [lindex $aux $i]} {
1247 set err
"Expected score was [lindex $aux $i] but got [$r zscore zscoretest $i] for element $i"
1254 test
{ZSCORE
after a DEBUG RELOAD
} {
1258 for {set i
0} {$i < 1000} {incr i
} {
1259 set score
[expr rand
()]
1261 $r zadd zscoretest
$score $i
1264 for {set i
0} {$i < 1000} {incr i
} {
1265 if {[$r zscore zscoretest
$i] != [lindex $aux $i]} {
1266 set err
"Expected score was [lindex $aux $i] but got [$r zscore zscoretest $i] for element $i"
1273 test
{ZRANGE and ZREVRANGE basics
} {
1274 list [$r zrange ztmp
0 -1] [$r zrevrange ztmp
0 -1] \
1275 [$r zrange ztmp
1 -1] [$r zrevrange ztmp
1 -1]
1276 } {{y x z
} {z x y
} {x z
} {x y
}}
1278 test
{ZRANGE WITHSCORES
} {
1279 $r zrange ztmp
0 -1 withscores
1282 test
{ZSETs stress tester
- sorting is working well?
} {
1284 for {set test
0} {$test < 2} {incr test
} {
1285 unset -nocomplain auxarray
1286 array set auxarray
{}
1289 for {set i
0} {$i < 1000} {incr i
} {
1291 set score
[expr rand
()]
1293 set score
[expr int
(rand
()*10)]
1295 set auxarray
($i) $score
1296 $r zadd myzset
$score $i
1298 if {[expr rand
()] < .2} {
1299 set j
[expr int
(rand
()*1000)]
1301 set score
[expr rand
()]
1303 set score
[expr int
(rand
()*10)]
1305 set auxarray
($j) $score
1306 $r zadd myzset
$score $j
1309 foreach {item score
} [array get auxarray
] {
1310 lappend auxlist
[list $score $item]
1312 set sorted
[lsort -command zlistAlikeSort
$auxlist]
1315 lappend auxlist
[lindex $x 1]
1317 set fromredis
[$r zrange myzset
0 -1]
1319 for {set i
0} {$i < [llength $fromredis]} {incr i
} {
1320 if {[lindex $fromredis $i] != [lindex $auxlist $i]} {
1328 test
{ZINCRBY
- can create a new sorted
set} {
1330 $r zincrby zset
1 foo
1331 list [$r zrange zset
0 -1] [$r zscore zset foo
]
1334 test
{ZINCRBY
- increment and decrement
} {
1335 $r zincrby zset
2 foo
1336 $r zincrby zset
1 bar
1337 set v1
[$r zrange zset
0 -1]
1338 $r zincrby zset
10 bar
1339 $r zincrby zset
-5 foo
1340 $r zincrby zset
-5 bar
1341 set v2
[$r zrange zset
0 -1]
1342 list $v1 $v2 [$r zscore zset foo
] [$r zscore zset bar
]
1343 } {{bar foo
} {foo bar
} -2 6}
1345 test
{ZRANGEBYSCORE and ZCOUNT basics
} {
1352 list [$r zrangebyscore zset
2 4] [$r zrangebyscore zset
(2 (4] \
1353 [$r zcount zset
2 4] [$r zcount zset
(2 (4]
1356 test
{ZRANGEBYSCORE withscores
} {
1363 $r zrangebyscore zset
2 4 withscores
1366 test
{ZRANGEBYSCORE fuzzy test
, 100 ranges in
1000 elements sorted
set} {
1369 for {set i
0} {$i < 1000} {incr i
} {
1370 $r zadd zset
[expr rand
()] $i
1372 for {set i
0} {$i < 100} {incr i
} {
1373 set min
[expr rand
()]
1374 set max
[expr rand
()]
1380 set low
[$r zrangebyscore zset
-inf $min]
1381 set ok
[$r zrangebyscore zset
$min $max]
1382 set high
[$r zrangebyscore zset
$max +inf
]
1383 set lowx
[$r zrangebyscore zset
-inf ($min]
1384 set okx
[$r zrangebyscore zset
($min ($max]
1385 set highx
[$r zrangebyscore zset
($max +inf
]
1387 if {[$r zcount zset
-inf $min] != [llength $low]} {
1388 append err
"Error, len does not match zcount\n"
1390 if {[$r zcount zset
$min $max] != [llength $ok]} {
1391 append err
"Error, len does not match zcount\n"
1393 if {[$r zcount zset
$max +inf
] != [llength $high]} {
1394 append err
"Error, len does not match zcount\n"
1396 if {[$r zcount zset
-inf ($min] != [llength $lowx]} {
1397 append err
"Error, len does not match zcount\n"
1399 if {[$r zcount zset
($min ($max] != [llength $okx]} {
1400 append err
"Error, len does not match zcount\n"
1402 if {[$r zcount zset
($max +inf
] != [llength $highx]} {
1403 append err
"Error, len does not match zcount\n"
1407 set score
[$r zscore zset
$x]
1408 if {$score > $min} {
1409 append err
"Error, score for $x is $score > $min\n"
1413 set score
[$r zscore zset
$x]
1414 if {$score >= $min} {
1415 append err
"Error, score for $x is $score >= $min\n"
1419 set score
[$r zscore zset
$x]
1420 if {$score < $min ||
$score > $max} {
1421 append err
"Error, score for $x is $score outside $min-$max range\n"
1425 set score
[$r zscore zset
$x]
1426 if {$score <= $min ||
$score >= $max} {
1427 append err
"Error, score for $x is $score outside $min-$max open range\n"
1431 set score
[$r zscore zset
$x]
1432 if {$score < $max} {
1433 append err
"Error, score for $x is $score < $max\n"
1437 set score
[$r zscore zset
$x]
1438 if {$score <= $max} {
1439 append err
"Error, score for $x is $score <= $max\n"
1446 test
{ZRANGEBYSCORE with LIMIT
} {
1454 [$r zrangebyscore zset
0 10 LIMIT
0 2] \
1455 [$r zrangebyscore zset
0 10 LIMIT
2 3] \
1456 [$r zrangebyscore zset
0 10 LIMIT
2 10] \
1457 [$r zrangebyscore zset
0 10 LIMIT
20 10]
1458 } {{a b
} {c d e
} {c d e
} {}}
1460 test
{ZRANGEBYSCORE with LIMIT and withscores
} {
1467 $r zrangebyscore zset
20 50 LIMIT
2 3 withscores
1470 test
{ZREMRANGEBYSCORE basics
} {
1477 list [$r zremrangebyscore zset
2 4] [$r zrange zset
0 -1]
1480 test
{ZREMRANGEBYSCORE from
-inf to
+inf
} {
1487 list [$r zremrangebyscore zset
-inf +inf
] [$r zrange zset
0 -1]
1490 test
{ZREMRANGEBYRANK basics
} {
1497 list [$r zremrangebyrank zset
1 3] [$r zrange zset
0 -1]
1500 test
{ZUNION against non-existing key doesn't
set destination
} {
1502 list [$r zunion dst_key
1 zseta
] [$r exists dst_key
]
1505 test
{ZUNION basics
} {
1506 $r del zseta zsetb zsetc
1513 list [$r zunion zsetc
2 zseta zsetb
] [$r zrange zsetc
0 -1 withscores
]
1514 } {4 {a
1 b
3 d
3 c
5}}
1516 test
{ZUNION with weights
} {
1517 list [$r zunion zsetc
2 zseta zsetb weights
2 3] [$r zrange zsetc
0 -1 withscores
]
1518 } {4 {a
2 b
7 d
9 c
12}}
1520 test
{ZUNION with AGGREGATE MIN
} {
1521 list [$r zunion zsetc
2 zseta zsetb aggregate min
] [$r zrange zsetc
0 -1 withscores
]
1522 } {4 {a
1 b
1 c
2 d
3}}
1524 test
{ZUNION with AGGREGATE MAX
} {
1525 list [$r zunion zsetc
2 zseta zsetb aggregate max
] [$r zrange zsetc
0 -1 withscores
]
1526 } {4 {a
1 b
2 c
3 d
3}}
1528 test
{ZINTER basics
} {
1529 list [$r zinter zsetc
2 zseta zsetb
] [$r zrange zsetc
0 -1 withscores
]
1532 test
{ZINTER with weights
} {
1533 list [$r zinter zsetc
2 zseta zsetb weights
2 3] [$r zrange zsetc
0 -1 withscores
]
1536 test
{ZINTER with AGGREGATE MIN
} {
1537 list [$r zinter zsetc
2 zseta zsetb aggregate min
] [$r zrange zsetc
0 -1 withscores
]
1540 test
{ZINTER with AGGREGATE MAX
} {
1541 list [$r zinter zsetc
2 zseta zsetb aggregate max
] [$r zrange zsetc
0 -1 withscores
]
1544 test
{SORT against sorted sets
} {
1551 $r sort zset alpha desc
1554 test
{Sorted sets
+inf and
-inf handling
} {
1559 $r zadd zset
1000000 d
1560 $r zadd zset
+inf max
1561 $r zadd zset
-inf min
1565 test
{HSET
/HLEN
- Small hash creation
} {
1566 array set smallhash
{}
1567 for {set i
0} {$i < 8} {incr i
} {
1568 set key
[randstring
0 8 alpha
]
1569 set val
[randstring
0 8 alpha
]
1570 if {[info exists smallhash
($key)]} {
1574 $r hset smallhash
$key $val
1575 set smallhash
($key) $val
1577 list [$r hlen smallhash
]
1580 test
{Is the small hash encoded with a zipmap?
} {
1581 $r debug object smallhash
1584 test
{HSET
/HLEN
- Big hash creation
} {
1585 array set bighash
{}
1586 for {set i
0} {$i < 1024} {incr i
} {
1587 set key
[randstring
0 8 alpha
]
1588 set val
[randstring
0 8 alpha
]
1589 if {[info exists bighash
($key)]} {
1593 $r hset bighash
$key $val
1594 set bighash
($key) $val
1596 list [$r hlen bighash
]
1599 test
{Is the big hash encoded with a zipmap?
} {
1600 $r debug object bighash
1603 test
{HGET against the small hash
} {
1605 foreach k
[array names smallhash
*] {
1606 if {$smallhash($k) ne
[$r hget smallhash
$k]} {
1607 set err
"$smallhash($k) != [$r hget smallhash $k]"
1614 test
{HGET against the big hash
} {
1616 foreach k
[array names bighash
*] {
1617 if {$bighash($k) ne
[$r hget bighash
$k]} {
1618 set err
"$bighash($k) != [$r hget bighash $k]"
1625 test
{HGET against non existing key
} {
1627 lappend rv
[$r hget smallhash __123123123__
]
1628 lappend rv
[$r hget bighash __123123123__
]
1632 test
{HSET in
update and insert mode
} {
1634 set k
[lindex [array names smallhash
*] 0]
1635 lappend rv
[$r hset smallhash
$k newval1
]
1636 set smallhash
($k) newval1
1637 lappend rv
[$r hget smallhash
$k]
1638 lappend rv
[$r hset smallhash __foobar123__ newval
]
1639 set k
[lindex [array names bighash
*] 0]
1640 lappend rv
[$r hset bighash
$k newval2
]
1641 set bighash
($k) newval2
1642 lappend rv
[$r hget bighash
$k]
1643 lappend rv
[$r hset bighash __foobar123__ newval
]
1644 lappend rv
[$r hdel smallhash __foobar123__
]
1645 lappend rv
[$r hdel bighash __foobar123__
]
1647 } {0 newval1
1 0 newval2
1 1 1}
1649 test
{HMSET wrong number of args
} {
1650 catch {$r hmset smallhash key1 val1 key2
} err
1654 test
{HMSET
- small hash
} {
1656 foreach {k v
} [array get smallhash
] {
1657 set newval
[randstring
0 8 alpha
]
1658 set smallhash
($k) $newval
1659 lappend args
$k $newval
1661 $r hmset smallhash
{*}$args
1664 test
{HMSET
- big hash
} {
1666 foreach {k v
} [array get bighash
] {
1667 set newval
[randstring
0 8 alpha
]
1668 set bighash
($k) $newval
1669 lappend args
$k $newval
1671 $r hmset bighash
{*}$args
1674 test
{HMGET against non existing key and fields
} {
1676 lappend rv
[$r hmget doesntexist __123123123__ __456456456__
]
1677 lappend rv
[$r hmget smallhash __123123123__ __456456456__
]
1678 lappend rv
[$r hmget bighash __123123123__ __456456456__
]
1680 } {{{} {}} {{} {}} {{} {}}}
1682 test
{HMGET
- small hash
} {
1685 foreach {k v
} [array get smallhash
] {
1690 set result
[$r hmget smallhash
{*}$keys]
1691 if {$vals ne
$result} {
1692 set err
"$vals != $result"
1698 test
{HMGET
- big hash
} {
1701 foreach {k v
} [array get bighash
] {
1706 set result
[$r hmget bighash
{*}$keys]
1707 if {$vals ne
$result} {
1708 set err
"$vals != $result"
1714 test
{HKEYS
- small hash
} {
1715 lsort [$r hkeys smallhash
]
1716 } [lsort [array names smallhash
*]]
1718 test
{HKEYS
- big hash
} {
1719 lsort [$r hkeys bighash
]
1720 } [lsort [array names bighash
*]]
1722 test
{HVALS
- small hash
} {
1724 foreach {k v
} [array get smallhash
] {
1728 } [lsort [$r hvals smallhash
]]
1730 test
{HVALS
- big hash
} {
1732 foreach {k v
} [array get bighash
] {
1736 } [lsort [$r hvals bighash
]]
1738 test
{HGETALL
- small hash
} {
1739 lsort [$r hgetall smallhash
]
1740 } [lsort [array get smallhash
]]
1742 test
{HGETALL
- big hash
} {
1743 lsort [$r hgetall bighash
]
1744 } [lsort [array get bighash
]]
1746 test
{HDEL and
return value
} {
1748 lappend rv
[$r hdel smallhash nokey
]
1749 lappend rv
[$r hdel bighash nokey
]
1750 set k
[lindex [array names smallhash
*] 0]
1751 lappend rv
[$r hdel smallhash
$k]
1752 lappend rv
[$r hdel smallhash
$k]
1753 lappend rv
[$r hget smallhash
$k]
1755 set k
[lindex [array names bighash
*] 0]
1756 lappend rv
[$r hdel bighash
$k]
1757 lappend rv
[$r hdel bighash
$k]
1758 lappend rv
[$r hget bighash
$k]
1761 } {0 0 1 0 {} 1 0 {}}
1765 set k
[lindex [array names smallhash
*] 0]
1766 lappend rv
[$r hexists smallhash
$k]
1767 lappend rv
[$r hexists smallhash nokey
]
1768 set k
[lindex [array names bighash
*] 0]
1769 lappend rv
[$r hexists bighash
$k]
1770 lappend rv
[$r hexists bighash nokey
]
1773 test
{Is a zipmap encoded Hash promoted on big payload?
} {
1774 $r hset smallhash foo
[string repeat a
1024]
1775 $r debug object smallhash
1778 test
{HINCRBY against non existing database key
} {
1780 list [$r hincrby htest foo
2]
1783 test
{HINCRBY against non existing hash key
} {
1785 $r hdel smallhash tmp
1787 lappend rv
[$r hincrby smallhash tmp
2]
1788 lappend rv
[$r hget smallhash tmp
]
1789 lappend rv
[$r hincrby bighash tmp
2]
1790 lappend rv
[$r hget bighash tmp
]
1793 test
{HINCRBY against hash key created by hincrby itself
} {
1795 lappend rv
[$r hincrby smallhash tmp
3]
1796 lappend rv
[$r hget smallhash tmp
]
1797 lappend rv
[$r hincrby bighash tmp
3]
1798 lappend rv
[$r hget bighash tmp
]
1801 test
{HINCRBY against hash key originally
set with HSET
} {
1802 $r hset smallhash tmp
100
1803 $r hset bighash tmp
100
1804 list [$r hincrby smallhash tmp
2] [$r hincrby bighash tmp
2]
1807 test
{HINCRBY over
32bit value
} {
1808 $r hset smallhash tmp
17179869184
1809 $r hset bighash tmp
17179869184
1810 list [$r hincrby smallhash tmp
1] [$r hincrby bighash tmp
1]
1811 } {17179869185 17179869185}
1813 test
{HINCRBY over
32bit value with over
32bit increment
} {
1814 $r hset smallhash tmp
17179869184
1815 $r hset bighash tmp
17179869184
1816 list [$r hincrby smallhash tmp
17179869184] [$r hincrby bighash tmp
17179869184]
1817 } {34359738368 34359738368}
1819 test
{HINCRBY against key with spaces
(no integer encoded
)} {
1820 $r hset smallhash tmp
" 11 "
1821 $r hset bighash tmp
" 11 "
1822 list [$r hincrby smallhash tmp
1] [$r hincrby bighash tmp
1]
1826 # Randomized test, small and big
1827 # .rdb / AOF consistency test should include hashes
1829 test
{EXPIRE
- don't
set timeouts multiple times
} {
1831 set v1
[$r expire x
5]
1833 set v3
[$r expire x
10]
1835 list $v1 $v2 $v3 $v4
1838 test
{EXPIRE
- It should be still possible to
read 'x'
} {
1842 test
{EXPIRE
- After
6 seconds the key should no longer be here
} {
1844 list [$r get x
] [$r exists x
]
1847 test
{EXPIRE
- Delete on write policy
} {
1855 test
{EXPIREAT
- Check
for EXPIRE alike behavior
} {
1858 $r expireat x
[expr [clock seconds
]+15]
1862 test
{ZSETs skiplist implementation backlink consistency test
} {
1865 for {set j
0} {$j < $elements} {incr j
} {
1866 $r zadd myzset
[expr rand
()] "Element-$j"
1867 $r zrem myzset
"Element-[expr int(rand()*$elements)]"
1869 set l1
[$r zrange myzset
0 -1]
1870 set l2
[$r zrevrange myzset
0 -1]
1871 for {set j
0} {$j < [llength $l1]} {incr j
} {
1872 if {[lindex $l1 $j] ne
[lindex $l2 end-
$j]} {
1879 test
{ZSETs ZRANK augmented skip
list stress testing
} {
1882 for {set k
0} {$k < 10000} {incr k
} {
1883 set i
[expr {$k%1000}]
1884 if {[expr rand
()] < .2} {
1887 set score
[expr rand
()]
1888 $r zadd myzset
$score $i
1890 set card
[$r zcard myzset
]
1892 set index
[randomInt
$card]
1893 set ele
[lindex [$r zrange myzset
$index $index] 0]
1894 set rank
[$r zrank myzset
$ele]
1895 if {$rank != $index} {
1896 set err
"$ele RANK is wrong! ($rank != $index)"
1904 foreach fuzztype
{binary alpha compr
} {
1905 test
"FUZZ stresser with data model $fuzztype" {
1907 for {set i
0} {$i < 10000} {incr i
} {
1908 set fuzz
[randstring
0 512 $fuzztype]
1910 set got
[$r get foo
]
1911 if {$got ne
$fuzz} {
1912 set err
[list $fuzz $got]
1931 test
{Handle an empty query well
} {
1933 puts -nonewline $fd "\r\n"
1938 test
{Negative multi bulk command does not create problems
} {
1940 puts -nonewline $fd "*-10\r\n"
1945 test
{Negative multi bulk payload
} {
1947 puts -nonewline $fd "SET x -10\r\n"
1952 test
{Too big bulk payload
} {
1954 puts -nonewline $fd "SET x 2000000000\r\n"
1957 } {*invalid bulk
*count
*}
1959 test
{Multi bulk request not followed by bulk args
} {
1961 puts -nonewline $fd "*1\r\nfoo\r\n"
1964 } {*protocol
error*}
1966 test
{Generic wrong number of args
} {
1967 catch {$r ping x y z
} err
1969 } {*wrong
*arguments
*ping
*}
1971 test
{SELECT an out of range DB
} {
1972 catch {$r select
1000000} err
1976 if {![catch {package require sha1
}]} {
1977 test
{Check consistency of different data types
after a reload
} {
1979 createComplexDataset
$r 10000
1980 set sha1
[datasetDigest
$r]
1982 set sha1_after
[datasetDigest
$r]
1983 expr {$sha1 eq
$sha1_after}
1986 test
{Same dataset digest
if saving
/reloading as AOF?
} {
1988 waitForBgrewriteaof
$r
1990 set sha1_after
[datasetDigest
$r]
1991 expr {$sha1 eq
$sha1_after}
1995 test
{EXPIRES
after a reload
(snapshot
+ append only
file)} {
2002 set e1
[expr {$ttl > 900 && $ttl <= 1000}]
2004 waitForBgrewriteaof
$r
2006 set e2
[expr {$ttl > 900 && $ttl <= 1000}]
2010 test
{PIPELINING stresser
(also a regression
for the old epoll bug
)} {
2011 set fd2
[socket 127.0.0.1 6379]
2012 fconfigure $fd2 -encoding binary -translation binary
2013 puts -nonewline $fd2 "SELECT 9\r\n"
2017 for {set i
0} {$i < 100000} {incr i
} {
2019 set val
"0000${i}0000"
2020 append q
"SET key:$i [string length $val]\r\n$val\r\n"
2021 puts -nonewline $fd2 $q
2023 append q
"GET key:$i\r\n"
2024 puts -nonewline $fd2 $q
2028 for {set i
0} {$i < 100000} {incr i
} {
2031 set count
[string range
$count 1 end
]
2032 set val
[read $fd2 $count]
2039 test
{MUTLI
/ EXEC basics
} {
2045 set v1
[$r lrange mylist
0 -1]
2049 } {QUEUED QUEUED
{{a b c
} PONG
}}
2057 set v1
[$r del mylist
]
2059 set v3
[$r lrange mylist
0 -1]
2061 } {QUEUED OK
{a b c
}}
2063 test
{APPEND basics
} {
2064 list [$r append foo bar
] [$r get foo
] \
2065 [$r append foo
100] [$r get foo
]
2068 test
{APPEND fuzzing
} {
2070 foreach type
{binary alpha compr
} {
2073 for {set i
0} {$i < 1000} {incr i
} {
2074 set bin
[randstring
0 10 $type]
2078 if {$buf != [$r get x
]} {
2079 set err
"Expected '$buf' found '[$r get x]'"
2086 # Leave the user with a clean DB before to exit
2091 lappend aux
[$r dbsize
]
2094 lappend aux
[$r dbsize
]
2097 test
{Perform a final SAVE to leave a clean DB on disk
} {
2102 if {[string match
{*Darwin
*} [exec uname
-a]]} {
2103 test
{Check
for memory leaks
} {
2104 exec leaks redis-server
2109 puts "\n[expr $::passed+$::failed] tests, $::passed passed, $::failed failed"
2110 if {$::failed > 0} {
2111 puts "\n*** WARNING!!! $::failed FAILED TESTS ***\n"
2120 set randkey
[expr int
(rand
()*10000)]
2121 set randval
[expr int
(rand
()*10000)]
2122 set randidx0
[expr int
(rand
()*10)]
2123 set randidx1
[expr int
(rand
()*10)]
2124 set cmd
[expr int
(rand
()*20)]
2126 if {$cmd == 0} {$r set $randkey $randval}
2127 if {$cmd == 1} {$r get
$randkey}
2128 if {$cmd == 2} {$r incr $randkey}
2129 if {$cmd == 3} {$r lpush
$randkey $randval}
2130 if {$cmd == 4} {$r rpop
$randkey}
2131 if {$cmd == 5} {$r del
$randkey}
2132 if {$cmd == 6} {$r llen
$randkey}
2133 if {$cmd == 7} {$r lrange $randkey $randidx0 $randidx1}
2134 if {$cmd == 8} {$r ltrim
$randkey $randidx0 $randidx1}
2135 if {$cmd == 9} {$r lindex $randkey $randidx0}
2136 if {$cmd == 10} {$r lset $randkey $randidx0 $randval}
2137 if {$cmd == 11} {$r sadd
$randkey $randval}
2138 if {$cmd == 12} {$r srem
$randkey $randval}
2139 if {$cmd == 13} {$r smove
$randkey $randval}
2140 if {$cmd == 14} {$r scard
$randkey}
2141 if {$cmd == 15} {$r expire
$randkey [expr $randval%60]}
2149 # Set a few configuration defaults
2150 set ::host 127.0.0.1
2158 for {set j
0} {$j < [llength $argv]} {incr j
} {
2159 set opt
[lindex $argv $j]
2160 set arg
[lindex $argv [expr $j+1]]
2161 set lastarg
[expr {$arg eq
{}}]
2162 if {$opt eq
{-h} && !$lastarg} {
2165 } elseif
{$opt eq
{-p} && !$lastarg} {
2168 } elseif
{$opt eq
{-stress}} {
2170 } elseif
{$opt eq
{--flush}} {
2172 } elseif
{$opt eq
{--first} && !$lastarg} {
2175 } elseif
{$opt eq
{--last} && !$lastarg} {
2179 puts "Wrong argument: $opt"
2184 # Before to run the test check if DB 9 and DB 10 are empty
2192 set db9size
[$r dbsize
]
2194 set db10size
[$r dbsize
]
2195 if {$db9size != 0 ||
$db10size != 0} {
2196 puts "Can't run the tests against DB 9 and 10: DBs are not empty."
2207 main
$::host $::port