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'"
27 if {![string match
{*0 leaks
*} [exec leaks redis-server
]]} {
28 puts "--------- Test $::testnum LEAKED! --------"
34 proc randstring
{min max
{type
binary}} {
35 set len
[expr {$min+int
(rand
()*($max-$min+1))}]
37 if {$type eq
{binary}} {
40 } elseif
{$type eq
{alpha
}} {
43 } elseif
{$type eq
{compr
}} {
48 append output
[format "%c" [expr {$minval+int
(rand
()*($maxval-$minval+1))}]]
54 # Useful for some test
55 proc zlistAlikeSort
{a b
} {
56 if {[lindex $a 0] > [lindex $b 0]} {return 1}
57 if {[lindex $a 0] < [lindex $b 0]} {return -1}
58 string compare
[lindex $a 1] [lindex $b 1]
61 proc waitForBgsave r
{
64 if {[string match
{*bgsave_in_progress
:1*} $i]} {
65 puts -nonewline "\nWaiting for background save to finish... "
74 proc waitForBgrewriteaof r
{
77 if {[string match
{*bgrewriteaof_in_progress
:1*} $i]} {
78 puts -nonewline "\nWaiting for background AOF rewrite to finish... "
87 proc randomInt
{max
} {
88 expr {int
(rand
()*$max)}
92 set path
[expr {int
(rand
()*[llength $args])}]
93 uplevel 1 [lindex $args $path]
98 # Small enough to likely collide
101 # 32 bit compressible signed/unsigned
102 randpath
{randomInt
2000000000} {randomInt
4000000000}
105 randpath
{randomInt
1000000000000}
108 randpath
{randstring
0 256 alpha
} \
109 {randstring
0 256 compr
} \
110 {randstring
0 256 binary}
116 # Small enough to likely collide
119 # 32 bit compressible signed/unsigned
120 randpath
{randomInt
2000000000} {randomInt
4000000000}
123 randpath
{randomInt
1000000000000}
126 randpath
{randstring
1 256 alpha
} \
127 {randstring
1 256 compr
}
131 proc createComplexDataset
{r ops
} {
132 for {set j
0} {$j < $ops} {incr j
} {
137 set d
[expr {rand
()}]
139 set d
[expr {rand
()}]
141 set d
[expr {rand
()}]
143 set d
[expr {rand
()}]
145 set d
[expr {rand
()}]
147 randpath
{set d
+inf
} {set d
-inf}
171 randpath
{$r lpush
$k $v} \
178 randpath
{$r sadd
$k $v} \
182 randpath
{$r zadd
$k $d $v} \
186 randpath
{$r hset
$k $f $v} \
193 proc datasetDigest r
{
194 set keys
[lsort [$r keys
*]]
200 set aux
[::sha1::sha1 -hex [$r get
$k]]
202 if {[$r llen
$k] == 0} {
205 set aux
[::sha1::sha1 -hex [$r lrange $k 0 -1]]
208 if {[$r scard
$k] == 0} {
211 set aux
[::sha1::sha1 -hex [lsort [$r smembers
$k]]]
214 if {[$r zcard
$k] == 0} {
217 set aux
[::sha1::sha1 -hex [$r zrange
$k 0 -1]]
220 if {[$r hlen
$k] == 0} {
223 set aux
[::sha1::sha1 -hex [lsort [$r hgetall
$k]]]
226 error "Type not supported: $t"
229 if {$aux eq
{}} continue
230 set digest
[::sha1::sha1 -hex [join [list $aux $digest $k] "\n"]]
236 set r
[redis
$::host $::port]
241 # The following AUTH test should be enabled only when requirepass
242 # <PASSWORD> is set in redis.conf and redis-server was started with
243 # redis.conf as the first argument.
245 #test {AUTH with requirepass in redis.conf} {
249 test
{DEL all keys to start with a clean DB
} {
250 foreach key
[$r keys
*] {$r del
$key}
254 test
{SET and GET an item
} {
259 test
{SET and GET an empty item
} {
264 test
{DEL against a single item
} {
273 list [$r del foo1 foo2 foo3 foo4
] [$r mget foo1 foo2 foo3
]
276 test
{KEYS with pattern
} {
277 foreach key
{key_x key_y key_z foo_a foo_b foo_c
} {
281 } {foo_a foo_b foo_c
}
283 test
{KEYS to get all keys
} {
285 } {foo_a foo_b foo_c key_x key_y key_z
}
291 test
{DEL all keys
} {
292 foreach key
[$r keys
*] {$r del
$key}
296 test
{Very big payload in GET
/SET
} {
297 set buf
[string repeat
"abcd" 1000000]
300 } [string repeat
"abcd" 1000000]
302 test
{Very big payload random access
} {
305 for {set j
0} {$j < 100} {incr j
} {
306 set size
[expr 1+[randomInt
100000]]
307 set buf
[string repeat
"pl-$j" $size]
309 $r set bigpayload_
$j $buf
311 for {set j
0} {$j < 1000} {incr j
} {
312 set index
[randomInt
100]
313 set buf
[$r get bigpayload_
$index]
314 if {$buf != $payload($index)} {
315 set err
"Values differ: I set '$payload($index)' but I read back '$buf'"
323 test
{SET
10000 numeric keys and access all them in reverse order
} {
325 for {set x
0} {$x < 10000} {incr x
} {
329 for {set x
9999} {$x >= 0} {incr x
-1} {
332 set err
"Eleemnt at position $x is $val instead of $x"
339 test
{DBSIZE should be
10101 now
} {
343 test
{INCR against non existing key
} {
345 append res
[$r incr novar
]
346 append res
[$r get novar
]
349 test
{INCR against key created by
incr itself
} {
353 test
{INCR against key originally
set with SET
} {
358 test
{INCR over
32bit value
} {
359 $r set novar
17179869184
363 test
{INCRBY over
32bit value with over
32bit increment
} {
364 $r set novar
17179869184
365 $r incrby novar
17179869184
368 test
{INCR fails against key with spaces
(no integer encoded
)} {
370 catch {$r incr novar
} err
374 test
{INCR fails against a key holding a
list} {
376 catch {$r incr novar
} err
381 test
{DECRBY over
32bit value with over
32bit increment
, negative res
} {
382 $r set novar
17179869184
383 $r decrby novar
17179869185
386 test
{SETNX target key missing
} {
387 $r setnx novar2 foobared
391 test
{SETNX target key exists
} {
392 $r setnx novar2 blabla
396 test
{SETNX will overwrite EXPIREing key
} {
406 append res
[$r exists newkey
]
408 append res
[$r exists newkey
]
411 test
{Zero length value in key. SET
/GET
/EXISTS
} {
413 set res
[$r get emptykey
]
414 append res
[$r exists emptykey
]
416 append res
[$r exists emptykey
]
419 test
{Commands pipelining
} {
421 puts -nonewline $fd "SET k1 4\r\nxyzk\r\nGET k1\r\nPING\r\n"
424 append res
[string match OK
* [::redis::redis_read_reply $fd]]
425 append res
[::redis::redis_read_reply $fd]
426 append res
[string match PONG
* [::redis::redis_read_reply $fd]]
430 test
{Non existing command
} {
431 catch {$r foobaredcommand
} err
432 string match ERR
* $err
435 test
{Basic LPUSH
, RPUSH
, LLENGTH
, LINDEX
} {
436 set res
[$r lpush mylist a
]
437 append res
[$r lpush mylist b
]
438 append res
[$r rpush mylist c
]
439 append res
[$r llen mylist
]
440 append res
[$r rpush anotherlist d
]
441 append res
[$r lpush anotherlist e
]
442 append res
[$r llen anotherlist
]
443 append res
[$r lindex mylist
0]
444 append res
[$r lindex mylist
1]
445 append res
[$r lindex mylist
2]
446 append res
[$r lindex anotherlist
0]
447 append res
[$r lindex anotherlist
1]
448 list $res [$r lindex mylist
100]
456 test
{Create a long
list and check every single element with LINDEX
} {
458 for {set i
0} {$i < 1000} {incr i
} {
461 for {set i
0} {$i < 1000} {incr i
} {
462 if {[$r lindex mylist
$i] eq
$i} {incr ok
}
463 if {[$r lindex mylist
[expr (-$i)-1]] eq
[expr 999-$i]} {
470 test
{Test elements with LINDEX in random access
} {
472 for {set i
0} {$i < 1000} {incr i
} {
473 set rint
[expr int
(rand
()*1000)]
474 if {[$r lindex mylist
$rint] eq
$rint} {incr ok
}
475 if {[$r lindex mylist
[expr (-$rint)-1]] eq
[expr 999-$rint]} {
482 test
{Check
if the
list is still ok
after a DEBUG RELOAD
} {
485 for {set i
0} {$i < 1000} {incr i
} {
486 set rint
[expr int
(rand
()*1000)]
487 if {[$r lindex mylist
$rint] eq
$rint} {incr ok
}
488 if {[$r lindex mylist
[expr (-$rint)-1]] eq
[expr 999-$rint]} {
495 test
{LLEN against non-list value
error} {
498 catch {$r llen mylist
} err
502 test
{LLEN against non existing key
} {
506 test
{LINDEX against non-list value
error} {
507 catch {$r lindex mylist
0} err
511 test
{LINDEX against non existing key
} {
512 $r lindex not-a-key
10
515 test
{LPUSH against non-list value
error} {
516 catch {$r lpush mylist
0} err
520 test
{RPUSH against non-list value
error} {
521 catch {$r rpush mylist
0} err
525 test
{RPOPLPUSH base case
} {
531 set v1
[$r rpoplpush mylist newlist
]
532 set v2
[$r rpoplpush mylist newlist
]
533 set l1
[$r lrange mylist
0 -1]
534 set l2
[$r lrange newlist
0 -1]
538 test
{RPOPLPUSH with the same
list as src and dst
} {
543 set l1
[$r lrange mylist
0 -1]
544 set v
[$r rpoplpush mylist mylist
]
545 set l2
[$r lrange mylist
0 -1]
547 } {{a b c
} c
{c a b
}}
549 test
{RPOPLPUSH target
list already exists
} {
557 set v1
[$r rpoplpush mylist newlist
]
558 set v2
[$r rpoplpush mylist newlist
]
559 set l1
[$r lrange mylist
0 -1]
560 set l2
[$r lrange newlist
0 -1]
562 } {d c
{a b
} {c d x
}}
564 test
{RPOPLPUSH against non existing key
} {
567 set v1
[$r rpoplpush mylist newlist
]
568 list $v1 [$r exists mylist
] [$r exists newlist
]
571 test
{RPOPLPUSH against non
list src key
} {
575 catch {$r rpoplpush mylist newlist
} err
576 list [$r type mylist
] [$r exists newlist
] [string range
$err 0 2]
579 test
{RPOPLPUSH against non
list dst key
} {
587 catch {$r rpoplpush mylist newlist
} err
588 list [$r lrange mylist
0 -1] [$r type newlist
] [string range
$err 0 2]
589 } {{a b c d
} string ERR
}
591 test
{RPOPLPUSH against non existing src key
} {
594 $r rpoplpush mylist newlist
597 test
{RENAME basic usage
} {
599 $r rename mykey mykey1
600 $r rename mykey1 mykey2
604 test
{RENAME
source key should no longer exist
} {
608 test
{RENAME against already existing key
} {
611 $r rename mykey2 mykey
612 set res
[$r get mykey
]
613 append res
[$r exists mykey2
]
616 test
{RENAMENX basic usage
} {
620 $r renamenx mykey mykey2
621 set res
[$r get mykey2
]
622 append res
[$r exists mykey
]
625 test
{RENAMENX against already existing key
} {
628 $r renamenx mykey mykey2
631 test
{RENAMENX against already existing key
(2)} {
632 set res
[$r get mykey
]
633 append res
[$r get mykey2
]
636 test
{RENAME against non existing
source key
} {
637 catch {$r rename nokey foobar
} err
641 test
{RENAME where
source and dest key is the same
} {
642 catch {$r rename mykey mykey
} err
646 test
{DEL all keys again
(DB
0)} {
647 foreach key
[$r keys
*] {
653 test
{DEL all keys again
(DB
1)} {
655 foreach key
[$r keys
*] {
663 test
{MOVE basic usage
} {
667 lappend res
[$r exists mykey
]
668 lappend res
[$r dbsize
]
670 lappend res
[$r get mykey
]
671 lappend res
[$r dbsize
]
674 } [list 0 0 foobar
1]
676 test
{MOVE against key existing in the target DB
} {
681 test
{SET
/GET keys in different DBs
} {
689 lappend res
[$r get a
]
690 lappend res
[$r get b
]
692 lappend res
[$r get a
]
693 lappend res
[$r get b
]
696 } {hello world foo bared
}
698 test
{Basic LPOP
/RPOP
} {
703 list [$r lpop mylist
] [$r rpop mylist
] [$r lpop mylist
] [$r llen mylist
]
706 test
{LPOP
/RPOP against empty
list} {
710 test
{LPOP against non
list value
} {
712 catch {$r lpop notalist
} err
716 test
{Mass LPUSH
/LPOP
} {
718 for {set i
0} {$i < 1000} {incr i
} {
723 for {set i
0} {$i < 500} {incr i
} {
724 incr sum2
[$r lpop mylist
]
725 incr sum2
[$r rpop mylist
]
730 test
{LRANGE basics
} {
731 for {set i
0} {$i < 10} {incr i
} {
734 list [$r lrange mylist
1 -2] \
735 [$r lrange mylist
-3 -1] \
736 [$r lrange mylist
4 4]
737 } {{1 2 3 4 5 6 7 8} {7 8 9} 4}
739 test
{LRANGE inverted indexes
} {
743 test
{LRANGE out of range indexes including the full
list} {
744 $r lrange mylist
-1000 1000
745 } {0 1 2 3 4 5 6 7 8 9}
747 test
{LRANGE against non existing key
} {
748 $r lrange nosuchkey
0 1
751 test
{LTRIM basics
} {
753 for {set i
0} {$i < 100} {incr i
} {
757 $r lrange mylist
0 -1
760 test
{LTRIM stress testing
} {
763 for {set i
0} {$i < 20} {incr i
} {
767 for {set j
0} {$j < 100} {incr j
} {
770 for {set i
0} {$i < 20} {incr i
} {
776 $r ltrim mylist
$a $b
777 if {[$r lrange mylist
0 -1] ne
[lrange $mylist $a $b]} {
778 set err
"[$r lrange mylist 0 -1] != [lrange $mylist $a $b]"
787 foreach x
{99 98 97 96 95} {
791 $r lset mylist
-1 bar
792 $r lrange mylist
0 -1
795 test
{LSET out of range index
} {
796 catch {$r lset mylist
10 foo
} err
800 test
{LSET against non existing key
} {
801 catch {$r lset nosuchkey
10 foo
} err
805 test
{LSET against non
list value
} {
807 catch {$r lset nolist
0 foo
} err
811 test
{SADD
, SCARD
, SISMEMBER
, SMEMBERS basics
} {
814 list [$r scard myset
] [$r sismember myset foo
] \
815 [$r sismember myset bar
] [$r sismember myset bla
] \
816 [lsort [$r smembers myset
]]
817 } {2 1 1 0 {bar foo
}}
819 test
{SADD adding the same element multiple times
} {
826 test
{SADD against non
set} {
827 catch {$r sadd mylist foo
} err
834 lsort [$r smembers myset
]
837 test
{Mass SADD and SINTER with two sets
} {
838 for {set i
0} {$i < 1000} {incr i
} {
840 $r sadd set2
[expr $i+995]
842 lsort [$r sinter set1 set2
]
843 } {995 996 997 998 999}
845 test
{SUNION with two sets
} {
846 lsort [$r sunion set1 set2
]
847 } [lsort -uniq "[$r smembers set1] [$r smembers set2]"]
849 test
{SINTERSTORE with two sets
} {
850 $r sinterstore setres set1 set2
851 lsort [$r smembers setres
]
852 } {995 996 997 998 999}
854 test
{SINTERSTORE with two sets
, after a DEBUG RELOAD
} {
856 $r sinterstore setres set1 set2
857 lsort [$r smembers setres
]
858 } {995 996 997 998 999}
860 test
{SUNIONSTORE with two sets
} {
861 $r sunionstore setres set1 set2
862 lsort [$r smembers setres
]
863 } [lsort -uniq "[$r smembers set1] [$r smembers set2]"]
865 test
{SUNIONSTORE against non existing keys
} {
867 list [$r sunionstore setres foo111 bar222
] [$r exists xxx
]
870 test
{SINTER against three sets
} {
875 lsort [$r sinter set1 set2 set3
]
878 test
{SINTERSTORE with three sets
} {
879 $r sinterstore setres set1 set2 set3
880 lsort [$r smembers setres
]
883 test
{SUNION with non existing keys
} {
884 lsort [$r sunion nokey1 set1 set2 nokey2
]
885 } [lsort -uniq "[$r smembers set1] [$r smembers set2]"]
887 test
{SDIFF with two sets
} {
888 for {set i
5} {$i < 1000} {incr i
} {
891 lsort [$r sdiff set1 set4
]
894 test
{SDIFF with three sets
} {
896 lsort [$r sdiff set1 set4 set5
]
899 test
{SDIFFSTORE with three sets
} {
900 $r sdiffstore sres set1 set4 set5
901 lsort [$r smembers sres
]
909 list [lsort [list [$r spop myset
] [$r spop myset
] [$r spop myset
]]] [$r scard myset
]
912 test
{SAVE
- make sure there are all the types as values
} {
913 # Wait for a background saving in progress to terminate
915 $r lpush mysavelist hello
916 $r lpush mysavelist world
918 $r set mynormalkey
{blablablba
}
919 $r zadd mytestzset
10 a
920 $r zadd mytestzset
20 b
921 $r zadd mytestzset
30 c
930 unset -nocomplain myset
932 for {set i
0} {$i < 100} {incr i
} {
933 set myset
([$r srandmember myset
]) 1
935 lsort [array names myset
]
938 test
{Create a random
list and a random
set} {
940 array set seenrand
{}
941 for {set i
0} {$i < 10000} {incr i
} {
943 # Make sure all the weights are different because
944 # Redis does not use a stable sort but Tcl does.
946 set rint
[expr int
(rand
()*1000000)]
948 set rint
[expr rand
()]
950 if {![info exists seenrand
($rint)]} break
952 set seenrand
($rint) x
954 $r sadd tosort-set
$i
955 $r set weight_
$i $rint
956 $r hset wobj_
$i weight
$rint
957 lappend tosort
[list $i $rint]
959 set sorted
[lsort -index 1 -real $tosort]
961 for {set i
0} {$i < 10000} {incr i
} {
962 lappend res
[lindex $sorted $i 0]
967 test
{SORT with BY against the newly created
list} {
968 $r sort tosort
{BY weight_
*}
971 test
{SORT with BY
(hash field
) against the newly created
list} {
972 $r sort tosort
{BY wobj_
*->weight
}
975 test
{SORT with BY
, but against the newly created
set} {
976 $r sort tosort-set
{BY weight_
*}
979 test
{SORT with BY
(hash field
), but against the newly created
set} {
980 $r sort tosort-set
{BY wobj_
*->weight
}
983 test
{SORT with BY and STORE against the newly created
list} {
984 $r sort tosort
{BY weight_
*} store sort-res
985 $r lrange sort-res
0 -1
988 test
{SORT with BY
(hash field
) and STORE against the newly created
list} {
989 $r sort tosort
{BY wobj_
*->weight
} store sort-res
990 $r lrange sort-res
0 -1
993 test
{SORT direct
, numeric
, against the newly created
list} {
995 } [lsort -integer $res]
997 test
{SORT decreasing sort
} {
998 $r sort tosort
{DESC
}
999 } [lsort -decreasing -integer $res]
1001 test
{SORT speed
, sorting
10000 elements
list using BY
, 100 times
} {
1002 set start
[clock clicks
-milliseconds]
1003 for {set i
0} {$i < 100} {incr i
} {
1004 set sorted
[$r sort tosort
{BY weight_
* LIMIT
0 10}]
1006 set elapsed
[expr [clock clicks
-milliseconds]-$start]
1007 puts -nonewline "\n Average time to sort: [expr double($elapsed)/100] milliseconds "
1012 test
{SORT speed
, as above but against hash field
} {
1013 set start
[clock clicks
-milliseconds]
1014 for {set i
0} {$i < 100} {incr i
} {
1015 set sorted
[$r sort tosort
{BY wobj_
*->weight LIMIT
0 10}]
1017 set elapsed
[expr [clock clicks
-milliseconds]-$start]
1018 puts -nonewline "\n Average time to sort: [expr double($elapsed)/100] milliseconds "
1023 test
{SORT speed
, sorting
10000 elements
list directly
, 100 times
} {
1024 set start
[clock clicks
-milliseconds]
1025 for {set i
0} {$i < 100} {incr i
} {
1026 set sorted
[$r sort tosort
{LIMIT
0 10}]
1028 set elapsed
[expr [clock clicks
-milliseconds]-$start]
1029 puts -nonewline "\n Average time to sort: [expr double($elapsed)/100] milliseconds "
1034 test
{SORT speed
, pseudo-sorting
10000 elements
list, BY
<const
>, 100 times
} {
1035 set start
[clock clicks
-milliseconds]
1036 for {set i
0} {$i < 100} {incr i
} {
1037 set sorted
[$r sort tosort
{BY nokey LIMIT
0 10}]
1039 set elapsed
[expr [clock clicks
-milliseconds]-$start]
1040 puts -nonewline "\n Average time to sort: [expr double($elapsed)/100] milliseconds "
1045 test
{SORT regression
for issue
#19, sorting floats} {
1047 foreach x
{1.1 5.10 3.10 7.44 2.1 5.75 6.12 0.25 1.15} {
1051 } [lsort -real {1.1 5.10 3.10 7.44 2.1 5.75 6.12 0.25 1.15}]
1053 test
{SORT with GET
#} {
1058 $r mset weight_1
10 weight_2
5 weight_3
30
1059 $r sort mylist BY weight_
* GET
#
1062 test
{SORT with constant GET
} {
1063 $r sort mylist GET foo
1066 test
{LREM
, remove all the occurrences
} {
1070 $r rpush mylist foobar
1071 $r rpush mylist foobared
1074 $r rpush mylist test
1076 set res
[$r lrem mylist
0 bar
]
1077 list [$r lrange mylist
0 -1] $res
1078 } {{foo foobar foobared zap test foo
} 2}
1080 test
{LREM
, remove the first occurrence
} {
1081 set res
[$r lrem mylist
1 foo
]
1082 list [$r lrange mylist
0 -1] $res
1083 } {{foobar foobared zap test foo
} 1}
1085 test
{LREM
, remove non existing element
} {
1086 set res
[$r lrem mylist
1 nosuchelement
]
1087 list [$r lrange mylist
0 -1] $res
1088 } {{foobar foobared zap test foo
} 0}
1090 test
{LREM
, starting from tail with negative count
} {
1094 $r rpush mylist foobar
1095 $r rpush mylist foobared
1098 $r rpush mylist test
1101 set res
[$r lrem mylist
-1 bar
]
1102 list [$r lrange mylist
0 -1] $res
1103 } {{foo bar foobar foobared zap test foo foo
} 1}
1105 test
{LREM
, starting from tail with negative count
(2)} {
1106 set res
[$r lrem mylist
-2 foo
]
1107 list [$r lrange mylist
0 -1] $res
1108 } {{foo bar foobar foobared zap test
} 2}
1110 test
{LREM
, deleting objects that may be encoded as integers
} {
1111 $r lpush myotherlist
1
1112 $r lpush myotherlist
2
1113 $r lpush myotherlist
3
1114 $r lrem myotherlist
1 2
1125 test
{MGET against non existing key
} {
1126 $r mget foo baazz bar
1129 test
{MGET against non-string key
} {
1132 $r mget foo baazz bar myset
1141 for {set i
0} {$i < 100} {incr i
} {
1142 set rkey
[$r randomkey
]
1143 if {$rkey eq
{foo
}} {
1146 if {$rkey eq
{bar
}} {
1150 list $foo_seen $bar_seen
1153 test
{RANDOMKEY against empty DB
} {
1158 test
{RANDOMKEY regression
1} {
1165 test
{GETSET
(set new value
)} {
1166 list [$r getset foo xyz
] [$r get foo
]
1169 test
{GETSET
(replace old value
)} {
1171 list [$r getset foo xyz
] [$r get foo
]
1174 test
{SMOVE basics
} {
1181 $r smove myset1 myset2 a
1182 list [lsort [$r smembers myset2
]] [lsort [$r smembers myset1
]]
1185 test
{SMOVE non existing key
} {
1186 list [$r smove myset1 myset2 foo
] [lsort [$r smembers myset2
]] [lsort [$r smembers myset1
]]
1187 } {0 {a x y z
} {b c
}}
1189 test
{SMOVE non existing src
set} {
1190 list [$r smove noset myset2 foo
] [lsort [$r smembers myset2
]]
1193 test
{SMOVE non existing dst
set} {
1194 list [$r smove myset2 myset3 y
] [lsort [$r smembers myset2
]] [lsort [$r smembers myset3
]]
1197 test
{SMOVE wrong src key type
} {
1199 catch {$r smove x myset2 foo
} err
1203 test
{SMOVE wrong dst key type
} {
1205 catch {$r smove myset2 x foo
} err
1209 test
{MSET base case
} {
1210 $r mset x
10 y
"foo bar" z
"x x x x x x x\n\n\r\n"
1212 } [list 10 {foo bar
} "x x x x x x x\n\n\r\n"]
1214 test
{MSET wrong number of args
} {
1215 catch {$r mset x
10 y
"foo bar" z
} err
1219 test
{MSETNX with already existent key
} {
1220 list [$r msetnx x1 xxx y2 yyy x
20] [$r exists x1
] [$r exists y2
]
1223 test
{MSETNX with not existing keys
} {
1224 list [$r msetnx x1 xxx y2 yyy
] [$r get x1
] [$r get y2
]
1227 test
{MSETNX should remove all the volatile keys even on
failure} {
1231 list [$r msetnx x A y B z C
] [$r mget x y z
]
1234 test
{ZSET basic ZADD and score
update} {
1238 set aux1
[$r zrange ztmp
0 -1]
1240 set aux2
[$r zrange ztmp
0 -1]
1244 test
{ZCARD basics
} {
1248 test
{ZCARD non existing key
} {
1249 $r zcard ztmp-blabla
1252 test
{ZRANK basics
} {
1253 $r zadd zranktmp
10 x
1254 $r zadd zranktmp
20 y
1255 $r zadd zranktmp
30 z
1256 list [$r zrank zranktmp x
] [$r zrank zranktmp y
] [$r zrank zranktmp z
]
1259 test
{ZREVRANK basics
} {
1260 list [$r zrevrank zranktmp x
] [$r zrevrank zranktmp y
] [$r zrevrank zranktmp z
]
1263 test
{ZRANK
- after deletion
} {
1265 list [$r zrank zranktmp x
] [$r zrank zranktmp z
]
1271 for {set i
0} {$i < 1000} {incr i
} {
1272 set score
[expr rand
()]
1274 $r zadd zscoretest
$score $i
1276 for {set i
0} {$i < 1000} {incr i
} {
1277 if {[$r zscore zscoretest
$i] != [lindex $aux $i]} {
1278 set err
"Expected score was [lindex $aux $i] but got [$r zscore zscoretest $i] for element $i"
1285 test
{ZSCORE
after a DEBUG RELOAD
} {
1289 for {set i
0} {$i < 1000} {incr i
} {
1290 set score
[expr rand
()]
1292 $r zadd zscoretest
$score $i
1295 for {set i
0} {$i < 1000} {incr i
} {
1296 if {[$r zscore zscoretest
$i] != [lindex $aux $i]} {
1297 set err
"Expected score was [lindex $aux $i] but got [$r zscore zscoretest $i] for element $i"
1304 test
{ZRANGE and ZREVRANGE basics
} {
1305 list [$r zrange ztmp
0 -1] [$r zrevrange ztmp
0 -1] \
1306 [$r zrange ztmp
1 -1] [$r zrevrange ztmp
1 -1]
1307 } {{y x z
} {z x y
} {x z
} {x y
}}
1309 test
{ZRANGE WITHSCORES
} {
1310 $r zrange ztmp
0 -1 withscores
1313 test
{ZSETs stress tester
- sorting is working well?
} {
1315 for {set test
0} {$test < 2} {incr test
} {
1316 unset -nocomplain auxarray
1317 array set auxarray
{}
1320 for {set i
0} {$i < 1000} {incr i
} {
1322 set score
[expr rand
()]
1324 set score
[expr int
(rand
()*10)]
1326 set auxarray
($i) $score
1327 $r zadd myzset
$score $i
1329 if {[expr rand
()] < .2} {
1330 set j
[expr int
(rand
()*1000)]
1332 set score
[expr rand
()]
1334 set score
[expr int
(rand
()*10)]
1336 set auxarray
($j) $score
1337 $r zadd myzset
$score $j
1340 foreach {item score
} [array get auxarray
] {
1341 lappend auxlist
[list $score $item]
1343 set sorted
[lsort -command zlistAlikeSort
$auxlist]
1346 lappend auxlist
[lindex $x 1]
1348 set fromredis
[$r zrange myzset
0 -1]
1350 for {set i
0} {$i < [llength $fromredis]} {incr i
} {
1351 if {[lindex $fromredis $i] != [lindex $auxlist $i]} {
1359 test
{ZINCRBY
- can create a new sorted
set} {
1361 $r zincrby zset
1 foo
1362 list [$r zrange zset
0 -1] [$r zscore zset foo
]
1365 test
{ZINCRBY
- increment and decrement
} {
1366 $r zincrby zset
2 foo
1367 $r zincrby zset
1 bar
1368 set v1
[$r zrange zset
0 -1]
1369 $r zincrby zset
10 bar
1370 $r zincrby zset
-5 foo
1371 $r zincrby zset
-5 bar
1372 set v2
[$r zrange zset
0 -1]
1373 list $v1 $v2 [$r zscore zset foo
] [$r zscore zset bar
]
1374 } {{bar foo
} {foo bar
} -2 6}
1376 test
{ZRANGEBYSCORE and ZCOUNT basics
} {
1383 list [$r zrangebyscore zset
2 4] [$r zrangebyscore zset
(2 (4] \
1384 [$r zcount zset
2 4] [$r zcount zset
(2 (4]
1387 test
{ZRANGEBYSCORE withscores
} {
1394 $r zrangebyscore zset
2 4 withscores
1397 test
{ZRANGEBYSCORE fuzzy test
, 100 ranges in
1000 elements sorted
set} {
1400 for {set i
0} {$i < 1000} {incr i
} {
1401 $r zadd zset
[expr rand
()] $i
1403 for {set i
0} {$i < 100} {incr i
} {
1404 set min
[expr rand
()]
1405 set max
[expr rand
()]
1411 set low
[$r zrangebyscore zset
-inf $min]
1412 set ok
[$r zrangebyscore zset
$min $max]
1413 set high
[$r zrangebyscore zset
$max +inf
]
1414 set lowx
[$r zrangebyscore zset
-inf ($min]
1415 set okx
[$r zrangebyscore zset
($min ($max]
1416 set highx
[$r zrangebyscore zset
($max +inf
]
1418 if {[$r zcount zset
-inf $min] != [llength $low]} {
1419 append err
"Error, len does not match zcount\n"
1421 if {[$r zcount zset
$min $max] != [llength $ok]} {
1422 append err
"Error, len does not match zcount\n"
1424 if {[$r zcount zset
$max +inf
] != [llength $high]} {
1425 append err
"Error, len does not match zcount\n"
1427 if {[$r zcount zset
-inf ($min] != [llength $lowx]} {
1428 append err
"Error, len does not match zcount\n"
1430 if {[$r zcount zset
($min ($max] != [llength $okx]} {
1431 append err
"Error, len does not match zcount\n"
1433 if {[$r zcount zset
($max +inf
] != [llength $highx]} {
1434 append err
"Error, len does not match zcount\n"
1438 set score
[$r zscore zset
$x]
1439 if {$score > $min} {
1440 append err
"Error, score for $x is $score > $min\n"
1444 set score
[$r zscore zset
$x]
1445 if {$score >= $min} {
1446 append err
"Error, score for $x is $score >= $min\n"
1450 set score
[$r zscore zset
$x]
1451 if {$score < $min ||
$score > $max} {
1452 append err
"Error, score for $x is $score outside $min-$max range\n"
1456 set score
[$r zscore zset
$x]
1457 if {$score <= $min ||
$score >= $max} {
1458 append err
"Error, score for $x is $score outside $min-$max open range\n"
1462 set score
[$r zscore zset
$x]
1463 if {$score < $max} {
1464 append err
"Error, score for $x is $score < $max\n"
1468 set score
[$r zscore zset
$x]
1469 if {$score <= $max} {
1470 append err
"Error, score for $x is $score <= $max\n"
1477 test
{ZRANGEBYSCORE with LIMIT
} {
1485 [$r zrangebyscore zset
0 10 LIMIT
0 2] \
1486 [$r zrangebyscore zset
0 10 LIMIT
2 3] \
1487 [$r zrangebyscore zset
0 10 LIMIT
2 10] \
1488 [$r zrangebyscore zset
0 10 LIMIT
20 10]
1489 } {{a b
} {c d e
} {c d e
} {}}
1491 test
{ZRANGEBYSCORE with LIMIT and withscores
} {
1498 $r zrangebyscore zset
20 50 LIMIT
2 3 withscores
1501 test
{ZREMRANGEBYSCORE basics
} {
1508 list [$r zremrangebyscore zset
2 4] [$r zrange zset
0 -1]
1511 test
{ZREMRANGEBYSCORE from
-inf to
+inf
} {
1518 list [$r zremrangebyscore zset
-inf +inf
] [$r zrange zset
0 -1]
1521 test
{ZREMRANGEBYRANK basics
} {
1528 list [$r zremrangebyrank zset
1 3] [$r zrange zset
0 -1]
1531 test
{ZUNION against non-existing key doesn't
set destination
} {
1533 list [$r zunion dst_key
1 zseta
] [$r exists dst_key
]
1536 test
{ZUNION basics
} {
1537 $r del zseta zsetb zsetc
1544 list [$r zunion zsetc
2 zseta zsetb
] [$r zrange zsetc
0 -1 withscores
]
1545 } {4 {a
1 b
3 d
3 c
5}}
1547 test
{ZUNION with weights
} {
1548 list [$r zunion zsetc
2 zseta zsetb weights
2 3] [$r zrange zsetc
0 -1 withscores
]
1549 } {4 {a
2 b
7 d
9 c
12}}
1551 test
{ZUNION with AGGREGATE MIN
} {
1552 list [$r zunion zsetc
2 zseta zsetb aggregate min
] [$r zrange zsetc
0 -1 withscores
]
1553 } {4 {a
1 b
1 c
2 d
3}}
1555 test
{ZUNION with AGGREGATE MAX
} {
1556 list [$r zunion zsetc
2 zseta zsetb aggregate max
] [$r zrange zsetc
0 -1 withscores
]
1557 } {4 {a
1 b
2 c
3 d
3}}
1559 test
{ZINTER basics
} {
1560 list [$r zinter zsetc
2 zseta zsetb
] [$r zrange zsetc
0 -1 withscores
]
1563 test
{ZINTER with weights
} {
1564 list [$r zinter zsetc
2 zseta zsetb weights
2 3] [$r zrange zsetc
0 -1 withscores
]
1567 test
{ZINTER with AGGREGATE MIN
} {
1568 list [$r zinter zsetc
2 zseta zsetb aggregate min
] [$r zrange zsetc
0 -1 withscores
]
1571 test
{ZINTER with AGGREGATE MAX
} {
1572 list [$r zinter zsetc
2 zseta zsetb aggregate max
] [$r zrange zsetc
0 -1 withscores
]
1575 test
{SORT against sorted sets
} {
1582 $r sort zset alpha desc
1585 test
{Sorted sets
+inf and
-inf handling
} {
1590 $r zadd zset
1000000 d
1591 $r zadd zset
+inf max
1592 $r zadd zset
-inf min
1596 test
{HSET
/HLEN
- Small hash creation
} {
1597 array set smallhash
{}
1598 for {set i
0} {$i < 8} {incr i
} {
1599 set key
[randstring
0 8 alpha
]
1600 set val
[randstring
0 8 alpha
]
1601 if {[info exists smallhash
($key)]} {
1605 $r hset smallhash
$key $val
1606 set smallhash
($key) $val
1608 list [$r hlen smallhash
]
1611 test
{Is the small hash encoded with a zipmap?
} {
1612 $r debug object smallhash
1615 test
{HSET
/HLEN
- Big hash creation
} {
1616 array set bighash
{}
1617 for {set i
0} {$i < 1024} {incr i
} {
1618 set key
[randstring
0 8 alpha
]
1619 set val
[randstring
0 8 alpha
]
1620 if {[info exists bighash
($key)]} {
1624 $r hset bighash
$key $val
1625 set bighash
($key) $val
1627 list [$r hlen bighash
]
1630 test
{Is the big hash encoded with a zipmap?
} {
1631 $r debug object bighash
1634 test
{HGET against the small hash
} {
1636 foreach k
[array names smallhash
*] {
1637 if {$smallhash($k) ne
[$r hget smallhash
$k]} {
1638 set err
"$smallhash($k) != [$r hget smallhash $k]"
1645 test
{HGET against the big hash
} {
1647 foreach k
[array names bighash
*] {
1648 if {$bighash($k) ne
[$r hget bighash
$k]} {
1649 set err
"$bighash($k) != [$r hget bighash $k]"
1656 test
{HGET against non existing key
} {
1658 lappend rv
[$r hget smallhash __123123123__
]
1659 lappend rv
[$r hget bighash __123123123__
]
1663 test
{HSET in
update and insert mode
} {
1665 set k
[lindex [array names smallhash
*] 0]
1666 lappend rv
[$r hset smallhash
$k newval1
]
1667 set smallhash
($k) newval1
1668 lappend rv
[$r hget smallhash
$k]
1669 lappend rv
[$r hset smallhash __foobar123__ newval
]
1670 set k
[lindex [array names bighash
*] 0]
1671 lappend rv
[$r hset bighash
$k newval2
]
1672 set bighash
($k) newval2
1673 lappend rv
[$r hget bighash
$k]
1674 lappend rv
[$r hset bighash __foobar123__ newval
]
1675 lappend rv
[$r hdel smallhash __foobar123__
]
1676 lappend rv
[$r hdel bighash __foobar123__
]
1678 } {0 newval1
1 0 newval2
1 1 1}
1680 test
{HSETNX target key missing
- small hash
} {
1681 $r hsetnx smallhash __123123123__ foo
1682 $r hget smallhash __123123123__
1685 test
{HSETNX target key exists
- small hash
} {
1686 $r hsetnx smallhash __123123123__ bar
1687 set result
[$r hget smallhash __123123123__
]
1688 $r hdel smallhash __123123123__
1692 test
{HSETNX target key missing
- big hash
} {
1693 $r hsetnx bighash __123123123__ foo
1694 $r hget bighash __123123123__
1697 test
{HSETNX target key exists
- big hash
} {
1698 $r hsetnx bighash __123123123__ bar
1699 set result
[$r hget bighash __123123123__
]
1700 $r hdel bighash __123123123__
1704 test
{HMSET wrong number of args
} {
1705 catch {$r hmset smallhash key1 val1 key2
} err
1709 test
{HMSET
- small hash
} {
1711 foreach {k v
} [array get smallhash
] {
1712 set newval
[randstring
0 8 alpha
]
1713 set smallhash
($k) $newval
1714 lappend args
$k $newval
1716 $r hmset smallhash
{*}$args
1719 test
{HMSET
- big hash
} {
1721 foreach {k v
} [array get bighash
] {
1722 set newval
[randstring
0 8 alpha
]
1723 set bighash
($k) $newval
1724 lappend args
$k $newval
1726 $r hmset bighash
{*}$args
1729 test
{HMGET against non existing key and fields
} {
1731 lappend rv
[$r hmget doesntexist __123123123__ __456456456__
]
1732 lappend rv
[$r hmget smallhash __123123123__ __456456456__
]
1733 lappend rv
[$r hmget bighash __123123123__ __456456456__
]
1735 } {{{} {}} {{} {}} {{} {}}}
1737 test
{HMGET
- small hash
} {
1740 foreach {k v
} [array get smallhash
] {
1745 set result
[$r hmget smallhash
{*}$keys]
1746 if {$vals ne
$result} {
1747 set err
"$vals != $result"
1753 test
{HMGET
- big hash
} {
1756 foreach {k v
} [array get bighash
] {
1761 set result
[$r hmget bighash
{*}$keys]
1762 if {$vals ne
$result} {
1763 set err
"$vals != $result"
1769 test
{HKEYS
- small hash
} {
1770 lsort [$r hkeys smallhash
]
1771 } [lsort [array names smallhash
*]]
1773 test
{HKEYS
- big hash
} {
1774 lsort [$r hkeys bighash
]
1775 } [lsort [array names bighash
*]]
1777 test
{HVALS
- small hash
} {
1779 foreach {k v
} [array get smallhash
] {
1783 } [lsort [$r hvals smallhash
]]
1785 test
{HVALS
- big hash
} {
1787 foreach {k v
} [array get bighash
] {
1791 } [lsort [$r hvals bighash
]]
1793 test
{HGETALL
- small hash
} {
1794 lsort [$r hgetall smallhash
]
1795 } [lsort [array get smallhash
]]
1797 test
{HGETALL
- big hash
} {
1798 lsort [$r hgetall bighash
]
1799 } [lsort [array get bighash
]]
1801 test
{HDEL and
return value
} {
1803 lappend rv
[$r hdel smallhash nokey
]
1804 lappend rv
[$r hdel bighash nokey
]
1805 set k
[lindex [array names smallhash
*] 0]
1806 lappend rv
[$r hdel smallhash
$k]
1807 lappend rv
[$r hdel smallhash
$k]
1808 lappend rv
[$r hget smallhash
$k]
1810 set k
[lindex [array names bighash
*] 0]
1811 lappend rv
[$r hdel bighash
$k]
1812 lappend rv
[$r hdel bighash
$k]
1813 lappend rv
[$r hget bighash
$k]
1816 } {0 0 1 0 {} 1 0 {}}
1820 set k
[lindex [array names smallhash
*] 0]
1821 lappend rv
[$r hexists smallhash
$k]
1822 lappend rv
[$r hexists smallhash nokey
]
1823 set k
[lindex [array names bighash
*] 0]
1824 lappend rv
[$r hexists bighash
$k]
1825 lappend rv
[$r hexists bighash nokey
]
1828 test
{Is a zipmap encoded Hash promoted on big payload?
} {
1829 $r hset smallhash foo
[string repeat a
1024]
1830 $r debug object smallhash
1833 test
{HINCRBY against non existing database key
} {
1835 list [$r hincrby htest foo
2]
1838 test
{HINCRBY against non existing hash key
} {
1840 $r hdel smallhash tmp
1842 lappend rv
[$r hincrby smallhash tmp
2]
1843 lappend rv
[$r hget smallhash tmp
]
1844 lappend rv
[$r hincrby bighash tmp
2]
1845 lappend rv
[$r hget bighash tmp
]
1848 test
{HINCRBY against hash key created by hincrby itself
} {
1850 lappend rv
[$r hincrby smallhash tmp
3]
1851 lappend rv
[$r hget smallhash tmp
]
1852 lappend rv
[$r hincrby bighash tmp
3]
1853 lappend rv
[$r hget bighash tmp
]
1856 test
{HINCRBY against hash key originally
set with HSET
} {
1857 $r hset smallhash tmp
100
1858 $r hset bighash tmp
100
1859 list [$r hincrby smallhash tmp
2] [$r hincrby bighash tmp
2]
1862 test
{HINCRBY over
32bit value
} {
1863 $r hset smallhash tmp
17179869184
1864 $r hset bighash tmp
17179869184
1865 list [$r hincrby smallhash tmp
1] [$r hincrby bighash tmp
1]
1866 } {17179869185 17179869185}
1868 test
{HINCRBY over
32bit value with over
32bit increment
} {
1869 $r hset smallhash tmp
17179869184
1870 $r hset bighash tmp
17179869184
1871 list [$r hincrby smallhash tmp
17179869184] [$r hincrby bighash tmp
17179869184]
1872 } {34359738368 34359738368}
1874 test
{HINCRBY against key with spaces
(no integer encoded
)} {
1875 $r hset smallhash tmp
" 11 "
1876 $r hset bighash tmp
" 11 "
1877 list [$r hincrby smallhash tmp
1] [$r hincrby bighash tmp
1]
1881 # Randomized test, small and big
1882 # .rdb / AOF consistency test should include hashes
1884 test
{EXPIRE
- don't
set timeouts multiple times
} {
1886 set v1
[$r expire x
5]
1888 set v3
[$r expire x
10]
1890 list $v1 $v2 $v3 $v4
1893 test
{EXPIRE
- It should be still possible to
read 'x'
} {
1897 test
{EXPIRE
- After
6 seconds the key should no longer be here
} {
1899 list [$r get x
] [$r exists x
]
1902 test
{EXPIRE
- Delete on write policy
} {
1910 test
{EXPIREAT
- Check
for EXPIRE alike behavior
} {
1913 $r expireat x
[expr [clock seconds
]+15]
1917 test
{ZSETs skiplist implementation backlink consistency test
} {
1920 for {set j
0} {$j < $elements} {incr j
} {
1921 $r zadd myzset
[expr rand
()] "Element-$j"
1922 $r zrem myzset
"Element-[expr int(rand()*$elements)]"
1924 set l1
[$r zrange myzset
0 -1]
1925 set l2
[$r zrevrange myzset
0 -1]
1926 for {set j
0} {$j < [llength $l1]} {incr j
} {
1927 if {[lindex $l1 $j] ne
[lindex $l2 end-
$j]} {
1934 test
{ZSETs ZRANK augmented skip
list stress testing
} {
1937 for {set k
0} {$k < 10000} {incr k
} {
1938 set i
[expr {$k%1000}]
1939 if {[expr rand
()] < .2} {
1942 set score
[expr rand
()]
1943 $r zadd myzset
$score $i
1945 set card
[$r zcard myzset
]
1947 set index
[randomInt
$card]
1948 set ele
[lindex [$r zrange myzset
$index $index] 0]
1949 set rank
[$r zrank myzset
$ele]
1950 if {$rank != $index} {
1951 set err
"$ele RANK is wrong! ($rank != $index)"
1959 foreach fuzztype
{binary alpha compr
} {
1960 test
"FUZZ stresser with data model $fuzztype" {
1962 for {set i
0} {$i < 10000} {incr i
} {
1963 set fuzz
[randstring
0 512 $fuzztype]
1965 set got
[$r get foo
]
1966 if {$got ne
$fuzz} {
1967 set err
[list $fuzz $got]
1986 test
{Handle an empty query well
} {
1988 puts -nonewline $fd "\r\n"
1993 test
{Negative multi bulk command does not create problems
} {
1995 puts -nonewline $fd "*-10\r\n"
2000 test
{Negative multi bulk payload
} {
2002 puts -nonewline $fd "SET x -10\r\n"
2007 test
{Too big bulk payload
} {
2009 puts -nonewline $fd "SET x 2000000000\r\n"
2012 } {*invalid bulk
*count
*}
2014 test
{Multi bulk request not followed by bulk args
} {
2016 puts -nonewline $fd "*1\r\nfoo\r\n"
2019 } {*protocol
error*}
2021 test
{Generic wrong number of args
} {
2022 catch {$r ping x y z
} err
2024 } {*wrong
*arguments
*ping
*}
2026 test
{SELECT an out of range DB
} {
2027 catch {$r select
1000000} err
2031 if {![catch {package require sha1
}]} {
2032 test
{Check consistency of different data types
after a reload
} {
2034 createComplexDataset
$r 10000
2035 set sha1
[datasetDigest
$r]
2037 set sha1_after
[datasetDigest
$r]
2038 expr {$sha1 eq
$sha1_after}
2041 test
{Same dataset digest
if saving
/reloading as AOF?
} {
2043 waitForBgrewriteaof
$r
2045 set sha1_after
[datasetDigest
$r]
2046 expr {$sha1 eq
$sha1_after}
2050 test
{EXPIRES
after a reload
(snapshot
+ append only
file)} {
2057 set e1
[expr {$ttl > 900 && $ttl <= 1000}]
2059 waitForBgrewriteaof
$r
2061 set e2
[expr {$ttl > 900 && $ttl <= 1000}]
2065 test
{PIPELINING stresser
(also a regression
for the old epoll bug
)} {
2066 set fd2
[socket $::host $::port]
2067 fconfigure $fd2 -encoding binary -translation binary
2068 puts -nonewline $fd2 "SELECT 9\r\n"
2072 for {set i
0} {$i < 100000} {incr i
} {
2074 set val
"0000${i}0000"
2075 append q
"SET key:$i [string length $val]\r\n$val\r\n"
2076 puts -nonewline $fd2 $q
2078 append q
"GET key:$i\r\n"
2079 puts -nonewline $fd2 $q
2083 for {set i
0} {$i < 100000} {incr i
} {
2086 set count
[string range
$count 1 end
]
2087 set val
[read $fd2 $count]
2094 test
{MUTLI
/ EXEC basics
} {
2100 set v1
[$r lrange mylist
0 -1]
2104 } {QUEUED QUEUED
{{a b c
} PONG
}}
2112 set v1
[$r del mylist
]
2114 set v3
[$r lrange mylist
0 -1]
2116 } {QUEUED OK
{a b c
}}
2118 test
{APPEND basics
} {
2119 list [$r append foo bar
] [$r get foo
] \
2120 [$r append foo
100] [$r get foo
]
2123 test
{APPEND fuzzing
} {
2125 foreach type
{binary alpha compr
} {
2128 for {set i
0} {$i < 1000} {incr i
} {
2129 set bin
[randstring
0 10 $type]
2133 if {$buf != [$r get x
]} {
2134 set err
"Expected '$buf' found '[$r get x]'"
2141 # Leave the user with a clean DB before to exit
2146 lappend aux
[$r dbsize
]
2149 lappend aux
[$r dbsize
]
2152 test
{Perform a final SAVE to leave a clean DB on disk
} {
2157 if {[string match
{*Darwin
*} [exec uname
-a]]} {
2158 test
{Check
for memory leaks
} {
2159 exec leaks redis-server
2164 puts "\n[expr $::passed+$::failed] tests, $::passed passed, $::failed failed"
2165 if {$::failed > 0} {
2166 puts "\n*** WARNING!!! $::failed FAILED TESTS ***\n"
2171 set r
[redis
$::host $::port]
2175 set randkey
[expr int
(rand
()*10000)]
2176 set randval
[expr int
(rand
()*10000)]
2177 set randidx0
[expr int
(rand
()*10)]
2178 set randidx1
[expr int
(rand
()*10)]
2179 set cmd
[expr int
(rand
()*20)]
2181 if {$cmd == 0} {$r set $randkey $randval}
2182 if {$cmd == 1} {$r get
$randkey}
2183 if {$cmd == 2} {$r incr $randkey}
2184 if {$cmd == 3} {$r lpush
$randkey $randval}
2185 if {$cmd == 4} {$r rpop
$randkey}
2186 if {$cmd == 5} {$r del
$randkey}
2187 if {$cmd == 6} {$r llen
$randkey}
2188 if {$cmd == 7} {$r lrange $randkey $randidx0 $randidx1}
2189 if {$cmd == 8} {$r ltrim
$randkey $randidx0 $randidx1}
2190 if {$cmd == 9} {$r lindex $randkey $randidx0}
2191 if {$cmd == 10} {$r lset $randkey $randidx0 $randval}
2192 if {$cmd == 11} {$r sadd
$randkey $randval}
2193 if {$cmd == 12} {$r srem
$randkey $randval}
2194 if {$cmd == 13} {$r smove
$randkey $randval}
2195 if {$cmd == 14} {$r scard
$randkey}
2196 if {$cmd == 15} {$r expire
$randkey [expr $randval%60]}
2204 # Set a few configuration defaults
2205 set ::host 127.0.0.1
2214 for {set j
0} {$j < [llength $argv]} {incr j
} {
2215 set opt
[lindex $argv $j]
2216 set arg
[lindex $argv [expr $j+1]]
2217 set lastarg
[expr {$arg eq
{}}]
2218 if {$opt eq
{-h} && !$lastarg} {
2221 } elseif
{$opt eq
{-p} && !$lastarg} {
2224 } elseif
{$opt eq
{--stress}} {
2226 } elseif
{$opt eq
{--trace-leaks
}} {
2228 } elseif
{$opt eq
{--flush}} {
2230 } elseif
{$opt eq
{--first} && !$lastarg} {
2233 } elseif
{$opt eq
{--last} && !$lastarg} {
2237 puts "Wrong argument: $opt"
2242 # Before to run the test check if DB 9 and DB 10 are empty
2243 set r
[redis
$::host $::port]
2250 set db9size
[$r dbsize
]
2252 set db10size
[$r dbsize
]
2253 if {$db9size != 0 ||
$db10size != 0} {
2254 puts "Can't run the tests against DB 9 and 10: DBs are not empty."
2262 puts "Testing Redis, host $::host, port $::port"