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
{
198 set r
[redis
$::host $::port]
203 # The following AUTH test should be enabled only when requirepass
204 # <PASSWORD> is set in redis.conf and redis-server was started with
205 # redis.conf as the first argument.
207 #test {AUTH with requirepass in redis.conf} {
211 test
{DEL all keys to start with a clean DB
} {
212 foreach key
[$r keys
*] {$r del
$key}
216 test
{SET and GET an item
} {
221 test
{SET and GET an empty item
} {
226 test
{DEL against a single item
} {
235 list [$r del foo1 foo2 foo3 foo4
] [$r mget foo1 foo2 foo3
]
238 test
{KEYS with pattern
} {
239 foreach key
{key_x key_y key_z foo_a foo_b foo_c
} {
243 } {foo_a foo_b foo_c
}
245 test
{KEYS to get all keys
} {
247 } {foo_a foo_b foo_c key_x key_y key_z
}
253 test
{DEL all keys
} {
254 foreach key
[$r keys
*] {$r del
$key}
258 test
{Very big payload in GET
/SET
} {
259 set buf
[string repeat
"abcd" 1000000]
262 } [string repeat
"abcd" 1000000]
264 test
{Very big payload random access
} {
267 for {set j
0} {$j < 100} {incr j
} {
268 set size
[expr 1+[randomInt
100000]]
269 set buf
[string repeat
"pl-$j" $size]
271 $r set bigpayload_
$j $buf
273 for {set j
0} {$j < 1000} {incr j
} {
274 set index
[randomInt
100]
275 set buf
[$r get bigpayload_
$index]
276 if {$buf != $payload($index)} {
277 set err
"Values differ: I set '$payload($index)' but I read back '$buf'"
285 test
{SET
10000 numeric keys and access all them in reverse order
} {
287 for {set x
0} {$x < 10000} {incr x
} {
291 for {set x
9999} {$x >= 0} {incr x
-1} {
294 set err
"Eleemnt at position $x is $val instead of $x"
301 test
{DBSIZE should be
10101 now
} {
305 test
{INCR against non existing key
} {
307 append res
[$r incr novar
]
308 append res
[$r get novar
]
311 test
{INCR against key created by
incr itself
} {
315 test
{INCR against key originally
set with SET
} {
320 test
{INCR over
32bit value
} {
321 $r set novar
17179869184
325 test
{INCRBY over
32bit value with over
32bit increment
} {
326 $r set novar
17179869184
327 $r incrby novar
17179869184
330 test
{INCR fails against key with spaces
(no integer encoded
)} {
332 catch {$r incr novar
} err
336 test
{INCR fails against a key holding a
list} {
338 catch {$r incr mylist
} err
343 test
{DECRBY over
32bit value with over
32bit increment
, negative res
} {
344 $r set novar
17179869184
345 $r decrby novar
17179869185
348 test
{SETNX target key missing
} {
349 $r setnx novar2 foobared
353 test
{SETNX target key exists
} {
354 $r setnx novar2 blabla
358 test
{SETNX will overwrite EXPIREing key
} {
368 append res
[$r exists newkey
]
370 append res
[$r exists newkey
]
373 test
{Zero length value in key. SET
/GET
/EXISTS
} {
375 set res
[$r get emptykey
]
376 append res
[$r exists emptykey
]
378 append res
[$r exists emptykey
]
381 test
{Commands pipelining
} {
383 puts -nonewline $fd "SET k1 4\r\nxyzk\r\nGET k1\r\nPING\r\n"
386 append res
[string match OK
* [::redis::redis_read_reply $fd]]
387 append res
[::redis::redis_read_reply $fd]
388 append res
[string match PONG
* [::redis::redis_read_reply $fd]]
392 test
{Non existing command
} {
393 catch {$r foobaredcommand
} err
394 string match ERR
* $err
397 test
{Basic LPUSH
, RPUSH
, LLENGTH
, LINDEX
} {
398 set res
[$r lpush mylist a
]
399 append res
[$r lpush mylist b
]
400 append res
[$r rpush mylist c
]
401 append res
[$r llen mylist
]
402 append res
[$r rpush anotherlist d
]
403 append res
[$r lpush anotherlist e
]
404 append res
[$r llen anotherlist
]
405 append res
[$r lindex mylist
0]
406 append res
[$r lindex mylist
1]
407 append res
[$r lindex mylist
2]
408 append res
[$r lindex anotherlist
0]
409 append res
[$r lindex anotherlist
1]
410 list $res [$r lindex mylist
100]
418 test
{Create a long
list and check every single element with LINDEX
} {
420 for {set i
0} {$i < 1000} {incr i
} {
423 for {set i
0} {$i < 1000} {incr i
} {
424 if {[$r lindex mylist
$i] eq
$i} {incr ok
}
425 if {[$r lindex mylist
[expr (-$i)-1]] eq
[expr 999-$i]} {
432 test
{Test elements with LINDEX in random access
} {
434 for {set i
0} {$i < 1000} {incr i
} {
435 set rint
[expr int
(rand
()*1000)]
436 if {[$r lindex mylist
$rint] eq
$rint} {incr ok
}
437 if {[$r lindex mylist
[expr (-$rint)-1]] eq
[expr 999-$rint]} {
444 test
{Check
if the
list is still ok
after a DEBUG RELOAD
} {
447 for {set i
0} {$i < 1000} {incr i
} {
448 set rint
[expr int
(rand
()*1000)]
449 if {[$r lindex mylist
$rint] eq
$rint} {incr ok
}
450 if {[$r lindex mylist
[expr (-$rint)-1]] eq
[expr 999-$rint]} {
457 test
{LLEN against non-list value
error} {
460 catch {$r llen mylist
} err
464 test
{LLEN against non existing key
} {
468 test
{LINDEX against non-list value
error} {
469 catch {$r lindex mylist
0} err
473 test
{LINDEX against non existing key
} {
474 $r lindex not-a-key
10
477 test
{LPUSH against non-list value
error} {
478 catch {$r lpush mylist
0} err
482 test
{RPUSH against non-list value
error} {
483 catch {$r rpush mylist
0} err
487 test
{RPOPLPUSH base case
} {
493 set v1
[$r rpoplpush mylist newlist
]
494 set v2
[$r rpoplpush mylist newlist
]
495 set l1
[$r lrange mylist
0 -1]
496 set l2
[$r lrange newlist
0 -1]
500 test
{RPOPLPUSH with the same
list as src and dst
} {
505 set l1
[$r lrange mylist
0 -1]
506 set v
[$r rpoplpush mylist mylist
]
507 set l2
[$r lrange mylist
0 -1]
509 } {{a b c
} c
{c a b
}}
511 test
{RPOPLPUSH target
list already exists
} {
519 set v1
[$r rpoplpush mylist newlist
]
520 set v2
[$r rpoplpush mylist newlist
]
521 set l1
[$r lrange mylist
0 -1]
522 set l2
[$r lrange newlist
0 -1]
524 } {d c
{a b
} {c d x
}}
526 test
{RPOPLPUSH against non existing key
} {
529 set v1
[$r rpoplpush mylist newlist
]
530 list $v1 [$r exists mylist
] [$r exists newlist
]
533 test
{RPOPLPUSH against non
list src key
} {
537 catch {$r rpoplpush mylist newlist
} err
538 list [$r type mylist
] [$r exists newlist
] [string range
$err 0 2]
541 test
{RPOPLPUSH against non
list dst key
} {
549 catch {$r rpoplpush mylist newlist
} err
550 list [$r lrange mylist
0 -1] [$r type newlist
] [string range
$err 0 2]
551 } {{a b c d
} string ERR
}
553 test
{RPOPLPUSH against non existing src key
} {
556 $r rpoplpush mylist newlist
559 test
{RENAME basic usage
} {
561 $r rename mykey mykey1
562 $r rename mykey1 mykey2
566 test
{RENAME
source key should no longer exist
} {
570 test
{RENAME against already existing key
} {
573 $r rename mykey2 mykey
574 set res
[$r get mykey
]
575 append res
[$r exists mykey2
]
578 test
{RENAMENX basic usage
} {
582 $r renamenx mykey mykey2
583 set res
[$r get mykey2
]
584 append res
[$r exists mykey
]
587 test
{RENAMENX against already existing key
} {
590 $r renamenx mykey mykey2
593 test
{RENAMENX against already existing key
(2)} {
594 set res
[$r get mykey
]
595 append res
[$r get mykey2
]
598 test
{RENAME against non existing
source key
} {
599 catch {$r rename nokey foobar
} err
603 test
{RENAME where
source and dest key is the same
} {
604 catch {$r rename mykey mykey
} err
608 test
{DEL all keys again
(DB
0)} {
609 foreach key
[$r keys
*] {
615 test
{DEL all keys again
(DB
1)} {
617 foreach key
[$r keys
*] {
625 test
{MOVE basic usage
} {
629 lappend res
[$r exists mykey
]
630 lappend res
[$r dbsize
]
632 lappend res
[$r get mykey
]
633 lappend res
[$r dbsize
]
636 } [list 0 0 foobar
1]
638 test
{MOVE against key existing in the target DB
} {
643 test
{SET
/GET keys in different DBs
} {
651 lappend res
[$r get a
]
652 lappend res
[$r get b
]
654 lappend res
[$r get a
]
655 lappend res
[$r get b
]
658 } {hello world foo bared
}
660 test
{Basic LPOP
/RPOP
} {
665 list [$r lpop mylist
] [$r rpop mylist
] [$r lpop mylist
] [$r llen mylist
]
668 test
{LPOP
/RPOP against empty
list} {
672 test
{LPOP against non
list value
} {
674 catch {$r lpop notalist
} err
678 test
{Mass LPUSH
/LPOP
} {
680 for {set i
0} {$i < 1000} {incr i
} {
685 for {set i
0} {$i < 500} {incr i
} {
686 incr sum2
[$r lpop mylist
]
687 incr sum2
[$r rpop mylist
]
692 test
{LRANGE basics
} {
693 for {set i
0} {$i < 10} {incr i
} {
696 list [$r lrange mylist
1 -2] \
697 [$r lrange mylist
-3 -1] \
698 [$r lrange mylist
4 4]
699 } {{1 2 3 4 5 6 7 8} {7 8 9} 4}
701 test
{LRANGE inverted indexes
} {
705 test
{LRANGE out of range indexes including the full
list} {
706 $r lrange mylist
-1000 1000
707 } {0 1 2 3 4 5 6 7 8 9}
709 test
{LRANGE against non existing key
} {
710 $r lrange nosuchkey
0 1
713 test
{LTRIM basics
} {
715 for {set i
0} {$i < 100} {incr i
} {
719 $r lrange mylist
0 -1
722 test
{LTRIM stress testing
} {
725 for {set i
0} {$i < 20} {incr i
} {
729 for {set j
0} {$j < 100} {incr j
} {
732 for {set i
0} {$i < 20} {incr i
} {
738 $r ltrim mylist
$a $b
739 if {[$r lrange mylist
0 -1] ne
[lrange $mylist $a $b]} {
740 set err
"[$r lrange mylist 0 -1] != [lrange $mylist $a $b]"
749 foreach x
{99 98 97 96 95} {
753 $r lset mylist
-1 bar
754 $r lrange mylist
0 -1
757 test
{LSET out of range index
} {
758 catch {$r lset mylist
10 foo
} err
762 test
{LSET against non existing key
} {
763 catch {$r lset nosuchkey
10 foo
} err
767 test
{LSET against non
list value
} {
769 catch {$r lset nolist
0 foo
} err
773 test
{SADD
, SCARD
, SISMEMBER
, SMEMBERS basics
} {
776 list [$r scard myset
] [$r sismember myset foo
] \
777 [$r sismember myset bar
] [$r sismember myset bla
] \
778 [lsort [$r smembers myset
]]
779 } {2 1 1 0 {bar foo
}}
781 test
{SADD adding the same element multiple times
} {
788 test
{SADD against non
set} {
789 catch {$r sadd mylist foo
} err
796 lsort [$r smembers myset
]
799 test
{Mass SADD and SINTER with two sets
} {
800 for {set i
0} {$i < 1000} {incr i
} {
802 $r sadd set2
[expr $i+995]
804 lsort [$r sinter set1 set2
]
805 } {995 996 997 998 999}
807 test
{SUNION with two sets
} {
808 lsort [$r sunion set1 set2
]
809 } [lsort -uniq "[$r smembers set1] [$r smembers set2]"]
811 test
{SINTERSTORE with two sets
} {
812 $r sinterstore setres set1 set2
813 lsort [$r smembers setres
]
814 } {995 996 997 998 999}
816 test
{SINTERSTORE with two sets
, after a DEBUG RELOAD
} {
818 $r sinterstore setres set1 set2
819 lsort [$r smembers setres
]
820 } {995 996 997 998 999}
822 test
{SUNIONSTORE with two sets
} {
823 $r sunionstore setres set1 set2
824 lsort [$r smembers setres
]
825 } [lsort -uniq "[$r smembers set1] [$r smembers set2]"]
827 test
{SUNIONSTORE against non existing keys
} {
829 list [$r sunionstore setres foo111 bar222
] [$r exists xxx
]
832 test
{SINTER against three sets
} {
837 lsort [$r sinter set1 set2 set3
]
840 test
{SINTERSTORE with three sets
} {
841 $r sinterstore setres set1 set2 set3
842 lsort [$r smembers setres
]
845 test
{SUNION with non existing keys
} {
846 lsort [$r sunion nokey1 set1 set2 nokey2
]
847 } [lsort -uniq "[$r smembers set1] [$r smembers set2]"]
849 test
{SDIFF with two sets
} {
850 for {set i
5} {$i < 1000} {incr i
} {
853 lsort [$r sdiff set1 set4
]
856 test
{SDIFF with three sets
} {
858 lsort [$r sdiff set1 set4 set5
]
861 test
{SDIFFSTORE with three sets
} {
862 $r sdiffstore sres set1 set4 set5
863 lsort [$r smembers sres
]
871 list [lsort [list [$r spop myset
] [$r spop myset
] [$r spop myset
]]] [$r scard myset
]
874 test
{SAVE
- make sure there are all the types as values
} {
875 # Wait for a background saving in progress to terminate
877 $r lpush mysavelist hello
878 $r lpush mysavelist world
880 $r set mynormalkey
{blablablba
}
881 $r zadd mytestzset
10 a
882 $r zadd mytestzset
20 b
883 $r zadd mytestzset
30 c
892 unset -nocomplain myset
894 for {set i
0} {$i < 100} {incr i
} {
895 set myset
([$r srandmember myset
]) 1
897 lsort [array names myset
]
900 test
{SORT ALPHA against integer encoded strings
} {
909 test
{Create a random
list and a random
set} {
911 array set seenrand
{}
912 for {set i
0} {$i < 10000} {incr i
} {
914 # Make sure all the weights are different because
915 # Redis does not use a stable sort but Tcl does.
917 set rint
[expr int
(rand
()*1000000)]
919 set rint
[expr rand
()]
921 if {![info exists seenrand
($rint)]} break
923 set seenrand
($rint) x
925 $r sadd tosort-set
$i
926 $r set weight_
$i $rint
927 $r hset wobj_
$i weight
$rint
928 lappend tosort
[list $i $rint]
930 set sorted
[lsort -index 1 -real $tosort]
932 for {set i
0} {$i < 10000} {incr i
} {
933 lappend res
[lindex $sorted $i 0]
938 test
{SORT with BY against the newly created
list} {
939 $r sort tosort
{BY weight_
*}
942 test
{SORT with BY
(hash field
) against the newly created
list} {
943 $r sort tosort
{BY wobj_
*->weight
}
946 test
{SORT with GET
(key
+hash
) with sanity check of each element
(list)} {
948 set l1
[$r sort tosort GET
# GET weight_*]
949 set l2
[$r sort tosort GET
# GET wobj_*->weight]
950 foreach {id1 w1
} $l1 {id2 w2
} $l2 {
951 set realweight
[$r get weight_
$id1]
953 set err
"ID mismatch $id1 != $id2"
956 if {$realweight != $w1 ||
$realweight != $w2} {
957 set err
"Weights mismatch! w1: $w1 w2: $w2 real: $realweight"
964 test
{SORT with BY
, but against the newly created
set} {
965 $r sort tosort-set
{BY weight_
*}
968 test
{SORT with BY
(hash field
), but against the newly created
set} {
969 $r sort tosort-set
{BY wobj_
*->weight
}
972 test
{SORT with BY and STORE against the newly created
list} {
973 $r sort tosort
{BY weight_
*} store sort-res
974 $r lrange sort-res
0 -1
977 test
{SORT with BY
(hash field
) and STORE against the newly created
list} {
978 $r sort tosort
{BY wobj_
*->weight
} store sort-res
979 $r lrange sort-res
0 -1
982 test
{SORT direct
, numeric
, against the newly created
list} {
984 } [lsort -integer $res]
986 test
{SORT decreasing sort
} {
987 $r sort tosort
{DESC
}
988 } [lsort -decreasing -integer $res]
990 test
{SORT speed
, sorting
10000 elements
list using BY
, 100 times
} {
991 set start
[clock clicks
-milliseconds]
992 for {set i
0} {$i < 100} {incr i
} {
993 set sorted
[$r sort tosort
{BY weight_
* LIMIT
0 10}]
995 set elapsed
[expr [clock clicks
-milliseconds]-$start]
996 puts -nonewline "\n Average time to sort: [expr double($elapsed)/100] milliseconds "
1001 test
{SORT speed
, as above but against hash field
} {
1002 set start
[clock clicks
-milliseconds]
1003 for {set i
0} {$i < 100} {incr i
} {
1004 set sorted
[$r sort tosort
{BY wobj_
*->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
, sorting
10000 elements
list directly
, 100 times
} {
1013 set start
[clock clicks
-milliseconds]
1014 for {set i
0} {$i < 100} {incr i
} {
1015 set sorted
[$r sort tosort
{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
, pseudo-sorting
10000 elements
list, BY
<const
>, 100 times
} {
1024 set start
[clock clicks
-milliseconds]
1025 for {set i
0} {$i < 100} {incr i
} {
1026 set sorted
[$r sort tosort
{BY nokey 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 regression
for issue
#19, sorting floats} {
1036 foreach x
{1.1 5.10 3.10 7.44 2.1 5.75 6.12 0.25 1.15} {
1040 } [lsort -real {1.1 5.10 3.10 7.44 2.1 5.75 6.12 0.25 1.15}]
1042 test
{SORT with GET
#} {
1047 $r mset weight_1
10 weight_2
5 weight_3
30
1048 $r sort mylist BY weight_
* GET
#
1051 test
{SORT with constant GET
} {
1052 $r sort mylist GET foo
1055 test
{LREM
, remove all the occurrences
} {
1059 $r rpush mylist foobar
1060 $r rpush mylist foobared
1063 $r rpush mylist test
1065 set res
[$r lrem mylist
0 bar
]
1066 list [$r lrange mylist
0 -1] $res
1067 } {{foo foobar foobared zap test foo
} 2}
1069 test
{LREM
, remove the first occurrence
} {
1070 set res
[$r lrem mylist
1 foo
]
1071 list [$r lrange mylist
0 -1] $res
1072 } {{foobar foobared zap test foo
} 1}
1074 test
{LREM
, remove non existing element
} {
1075 set res
[$r lrem mylist
1 nosuchelement
]
1076 list [$r lrange mylist
0 -1] $res
1077 } {{foobar foobared zap test foo
} 0}
1079 test
{LREM
, starting from tail with negative count
} {
1083 $r rpush mylist foobar
1084 $r rpush mylist foobared
1087 $r rpush mylist test
1090 set res
[$r lrem mylist
-1 bar
]
1091 list [$r lrange mylist
0 -1] $res
1092 } {{foo bar foobar foobared zap test foo foo
} 1}
1094 test
{LREM
, starting from tail with negative count
(2)} {
1095 set res
[$r lrem mylist
-2 foo
]
1096 list [$r lrange mylist
0 -1] $res
1097 } {{foo bar foobar foobared zap test
} 2}
1099 test
{LREM
, deleting objects that may be encoded as integers
} {
1100 $r lpush myotherlist
1
1101 $r lpush myotherlist
2
1102 $r lpush myotherlist
3
1103 $r lrem myotherlist
1 2
1114 test
{MGET against non existing key
} {
1115 $r mget foo baazz bar
1118 test
{MGET against non-string key
} {
1121 $r mget foo baazz bar myset
1130 for {set i
0} {$i < 100} {incr i
} {
1131 set rkey
[$r randomkey
]
1132 if {$rkey eq
{foo
}} {
1135 if {$rkey eq
{bar
}} {
1139 list $foo_seen $bar_seen
1142 test
{RANDOMKEY against empty DB
} {
1147 test
{RANDOMKEY regression
1} {
1154 test
{GETSET
(set new value
)} {
1155 list [$r getset foo xyz
] [$r get foo
]
1158 test
{GETSET
(replace old value
)} {
1160 list [$r getset foo xyz
] [$r get foo
]
1163 test
{SMOVE basics
} {
1170 $r smove myset1 myset2 a
1171 list [lsort [$r smembers myset2
]] [lsort [$r smembers myset1
]]
1174 test
{SMOVE non existing key
} {
1175 list [$r smove myset1 myset2 foo
] [lsort [$r smembers myset2
]] [lsort [$r smembers myset1
]]
1176 } {0 {a x y z
} {b c
}}
1178 test
{SMOVE non existing src
set} {
1179 list [$r smove noset myset2 foo
] [lsort [$r smembers myset2
]]
1182 test
{SMOVE non existing dst
set} {
1183 list [$r smove myset2 myset3 y
] [lsort [$r smembers myset2
]] [lsort [$r smembers myset3
]]
1186 test
{SMOVE wrong src key type
} {
1188 catch {$r smove x myset2 foo
} err
1192 test
{SMOVE wrong dst key type
} {
1194 catch {$r smove myset2 x foo
} err
1198 test
{MSET base case
} {
1199 $r mset x
10 y
"foo bar" z
"x x x x x x x\n\n\r\n"
1201 } [list 10 {foo bar
} "x x x x x x x\n\n\r\n"]
1203 test
{MSET wrong number of args
} {
1204 catch {$r mset x
10 y
"foo bar" z
} err
1208 test
{MSETNX with already existent key
} {
1209 list [$r msetnx x1 xxx y2 yyy x
20] [$r exists x1
] [$r exists y2
]
1212 test
{MSETNX with not existing keys
} {
1213 list [$r msetnx x1 xxx y2 yyy
] [$r get x1
] [$r get y2
]
1216 test
{MSETNX should remove all the volatile keys even on
failure} {
1220 list [$r msetnx x A y B z C
] [$r mget x y z
]
1223 test
{ZSET basic ZADD and score
update} {
1227 set aux1
[$r zrange ztmp
0 -1]
1229 set aux2
[$r zrange ztmp
0 -1]
1233 test
{ZCARD basics
} {
1237 test
{ZCARD non existing key
} {
1238 $r zcard ztmp-blabla
1241 test
{ZRANK basics
} {
1242 $r zadd zranktmp
10 x
1243 $r zadd zranktmp
20 y
1244 $r zadd zranktmp
30 z
1245 list [$r zrank zranktmp x
] [$r zrank zranktmp y
] [$r zrank zranktmp z
]
1248 test
{ZREVRANK basics
} {
1249 list [$r zrevrank zranktmp x
] [$r zrevrank zranktmp y
] [$r zrevrank zranktmp z
]
1252 test
{ZRANK
- after deletion
} {
1254 list [$r zrank zranktmp x
] [$r zrank zranktmp z
]
1260 for {set i
0} {$i < 1000} {incr i
} {
1261 set score
[expr rand
()]
1263 $r zadd zscoretest
$score $i
1265 for {set i
0} {$i < 1000} {incr i
} {
1266 if {[$r zscore zscoretest
$i] != [lindex $aux $i]} {
1267 set err
"Expected score was [lindex $aux $i] but got [$r zscore zscoretest $i] for element $i"
1274 test
{ZSCORE
after a DEBUG RELOAD
} {
1278 for {set i
0} {$i < 1000} {incr i
} {
1279 set score
[expr rand
()]
1281 $r zadd zscoretest
$score $i
1284 for {set i
0} {$i < 1000} {incr i
} {
1285 if {[$r zscore zscoretest
$i] != [lindex $aux $i]} {
1286 set err
"Expected score was [lindex $aux $i] but got [$r zscore zscoretest $i] for element $i"
1293 test
{ZRANGE and ZREVRANGE basics
} {
1294 list [$r zrange ztmp
0 -1] [$r zrevrange ztmp
0 -1] \
1295 [$r zrange ztmp
1 -1] [$r zrevrange ztmp
1 -1]
1296 } {{y x z
} {z x y
} {x z
} {x y
}}
1298 test
{ZRANGE WITHSCORES
} {
1299 $r zrange ztmp
0 -1 withscores
1302 test
{ZSETs stress tester
- sorting is working well?
} {
1304 for {set test
0} {$test < 2} {incr test
} {
1305 unset -nocomplain auxarray
1306 array set auxarray
{}
1309 for {set i
0} {$i < 1000} {incr i
} {
1311 set score
[expr rand
()]
1313 set score
[expr int
(rand
()*10)]
1315 set auxarray
($i) $score
1316 $r zadd myzset
$score $i
1318 if {[expr rand
()] < .2} {
1319 set j
[expr int
(rand
()*1000)]
1321 set score
[expr rand
()]
1323 set score
[expr int
(rand
()*10)]
1325 set auxarray
($j) $score
1326 $r zadd myzset
$score $j
1329 foreach {item score
} [array get auxarray
] {
1330 lappend auxlist
[list $score $item]
1332 set sorted
[lsort -command zlistAlikeSort
$auxlist]
1335 lappend auxlist
[lindex $x 1]
1337 set fromredis
[$r zrange myzset
0 -1]
1339 for {set i
0} {$i < [llength $fromredis]} {incr i
} {
1340 if {[lindex $fromredis $i] != [lindex $auxlist $i]} {
1348 test
{ZINCRBY
- can create a new sorted
set} {
1350 $r zincrby zset
1 foo
1351 list [$r zrange zset
0 -1] [$r zscore zset foo
]
1354 test
{ZINCRBY
- increment and decrement
} {
1355 $r zincrby zset
2 foo
1356 $r zincrby zset
1 bar
1357 set v1
[$r zrange zset
0 -1]
1358 $r zincrby zset
10 bar
1359 $r zincrby zset
-5 foo
1360 $r zincrby zset
-5 bar
1361 set v2
[$r zrange zset
0 -1]
1362 list $v1 $v2 [$r zscore zset foo
] [$r zscore zset bar
]
1363 } {{bar foo
} {foo bar
} -2 6}
1365 test
{ZRANGEBYSCORE and ZCOUNT basics
} {
1372 list [$r zrangebyscore zset
2 4] [$r zrangebyscore zset
(2 (4] \
1373 [$r zcount zset
2 4] [$r zcount zset
(2 (4]
1376 test
{ZRANGEBYSCORE withscores
} {
1383 $r zrangebyscore zset
2 4 withscores
1386 test
{ZRANGEBYSCORE fuzzy test
, 100 ranges in
1000 elements sorted
set} {
1389 for {set i
0} {$i < 1000} {incr i
} {
1390 $r zadd zset
[expr rand
()] $i
1392 for {set i
0} {$i < 100} {incr i
} {
1393 set min
[expr rand
()]
1394 set max
[expr rand
()]
1400 set low
[$r zrangebyscore zset
-inf $min]
1401 set ok
[$r zrangebyscore zset
$min $max]
1402 set high
[$r zrangebyscore zset
$max +inf
]
1403 set lowx
[$r zrangebyscore zset
-inf ($min]
1404 set okx
[$r zrangebyscore zset
($min ($max]
1405 set highx
[$r zrangebyscore zset
($max +inf
]
1407 if {[$r zcount zset
-inf $min] != [llength $low]} {
1408 append err
"Error, len does not match zcount\n"
1410 if {[$r zcount zset
$min $max] != [llength $ok]} {
1411 append err
"Error, len does not match zcount\n"
1413 if {[$r zcount zset
$max +inf
] != [llength $high]} {
1414 append err
"Error, len does not match zcount\n"
1416 if {[$r zcount zset
-inf ($min] != [llength $lowx]} {
1417 append err
"Error, len does not match zcount\n"
1419 if {[$r zcount zset
($min ($max] != [llength $okx]} {
1420 append err
"Error, len does not match zcount\n"
1422 if {[$r zcount zset
($max +inf
] != [llength $highx]} {
1423 append err
"Error, len does not match zcount\n"
1427 set score
[$r zscore zset
$x]
1428 if {$score > $min} {
1429 append err
"Error, score for $x is $score > $min\n"
1433 set score
[$r zscore zset
$x]
1434 if {$score >= $min} {
1435 append err
"Error, score for $x is $score >= $min\n"
1439 set score
[$r zscore zset
$x]
1440 if {$score < $min ||
$score > $max} {
1441 append err
"Error, score for $x is $score outside $min-$max range\n"
1445 set score
[$r zscore zset
$x]
1446 if {$score <= $min ||
$score >= $max} {
1447 append err
"Error, score for $x is $score outside $min-$max open range\n"
1451 set score
[$r zscore zset
$x]
1452 if {$score < $max} {
1453 append err
"Error, score for $x is $score < $max\n"
1457 set score
[$r zscore zset
$x]
1458 if {$score <= $max} {
1459 append err
"Error, score for $x is $score <= $max\n"
1466 test
{ZRANGEBYSCORE with LIMIT
} {
1474 [$r zrangebyscore zset
0 10 LIMIT
0 2] \
1475 [$r zrangebyscore zset
0 10 LIMIT
2 3] \
1476 [$r zrangebyscore zset
0 10 LIMIT
2 10] \
1477 [$r zrangebyscore zset
0 10 LIMIT
20 10]
1478 } {{a b
} {c d e
} {c d e
} {}}
1480 test
{ZRANGEBYSCORE with LIMIT and withscores
} {
1487 $r zrangebyscore zset
20 50 LIMIT
2 3 withscores
1490 test
{ZREMRANGEBYSCORE basics
} {
1497 list [$r zremrangebyscore zset
2 4] [$r zrange zset
0 -1]
1500 test
{ZREMRANGEBYSCORE from
-inf to
+inf
} {
1507 list [$r zremrangebyscore zset
-inf +inf
] [$r zrange zset
0 -1]
1510 test
{ZREMRANGEBYRANK basics
} {
1517 list [$r zremrangebyrank zset
1 3] [$r zrange zset
0 -1]
1520 test
{ZUNION against non-existing key doesn't
set destination
} {
1522 list [$r zunion dst_key
1 zseta
] [$r exists dst_key
]
1525 test
{ZUNION basics
} {
1526 $r del zseta zsetb zsetc
1533 list [$r zunion zsetc
2 zseta zsetb
] [$r zrange zsetc
0 -1 withscores
]
1534 } {4 {a
1 b
3 d
3 c
5}}
1536 test
{ZUNION with weights
} {
1537 list [$r zunion zsetc
2 zseta zsetb weights
2 3] [$r zrange zsetc
0 -1 withscores
]
1538 } {4 {a
2 b
7 d
9 c
12}}
1540 test
{ZUNION with AGGREGATE MIN
} {
1541 list [$r zunion zsetc
2 zseta zsetb aggregate min
] [$r zrange zsetc
0 -1 withscores
]
1542 } {4 {a
1 b
1 c
2 d
3}}
1544 test
{ZUNION with AGGREGATE MAX
} {
1545 list [$r zunion zsetc
2 zseta zsetb aggregate max
] [$r zrange zsetc
0 -1 withscores
]
1546 } {4 {a
1 b
2 c
3 d
3}}
1548 test
{ZINTER basics
} {
1549 list [$r zinter zsetc
2 zseta zsetb
] [$r zrange zsetc
0 -1 withscores
]
1552 test
{ZINTER with weights
} {
1553 list [$r zinter zsetc
2 zseta zsetb weights
2 3] [$r zrange zsetc
0 -1 withscores
]
1556 test
{ZINTER with AGGREGATE MIN
} {
1557 list [$r zinter zsetc
2 zseta zsetb aggregate min
] [$r zrange zsetc
0 -1 withscores
]
1560 test
{ZINTER with AGGREGATE MAX
} {
1561 list [$r zinter zsetc
2 zseta zsetb aggregate max
] [$r zrange zsetc
0 -1 withscores
]
1564 test
{SORT against sorted sets
} {
1571 $r sort zset alpha desc
1574 test
{Sorted sets
+inf and
-inf handling
} {
1579 $r zadd zset
1000000 d
1580 $r zadd zset
+inf max
1581 $r zadd zset
-inf min
1585 test
{HSET
/HLEN
- Small hash creation
} {
1586 array set smallhash
{}
1587 for {set i
0} {$i < 8} {incr i
} {
1588 set key
[randstring
0 8 alpha
]
1589 set val
[randstring
0 8 alpha
]
1590 if {[info exists smallhash
($key)]} {
1594 $r hset smallhash
$key $val
1595 set smallhash
($key) $val
1597 list [$r hlen smallhash
]
1600 test
{Is the small hash encoded with a zipmap?
} {
1601 $r debug object smallhash
1604 test
{HSET
/HLEN
- Big hash creation
} {
1605 array set bighash
{}
1606 for {set i
0} {$i < 1024} {incr i
} {
1607 set key
[randstring
0 8 alpha
]
1608 set val
[randstring
0 8 alpha
]
1609 if {[info exists bighash
($key)]} {
1613 $r hset bighash
$key $val
1614 set bighash
($key) $val
1616 list [$r hlen bighash
]
1619 test
{Is the big hash encoded with a zipmap?
} {
1620 $r debug object bighash
1623 test
{HGET against the small hash
} {
1625 foreach k
[array names smallhash
*] {
1626 if {$smallhash($k) ne
[$r hget smallhash
$k]} {
1627 set err
"$smallhash($k) != [$r hget smallhash $k]"
1634 test
{HGET against the big hash
} {
1636 foreach k
[array names bighash
*] {
1637 if {$bighash($k) ne
[$r hget bighash
$k]} {
1638 set err
"$bighash($k) != [$r hget bighash $k]"
1645 test
{HGET against non existing key
} {
1647 lappend rv
[$r hget smallhash __123123123__
]
1648 lappend rv
[$r hget bighash __123123123__
]
1652 test
{HSET in
update and insert mode
} {
1654 set k
[lindex [array names smallhash
*] 0]
1655 lappend rv
[$r hset smallhash
$k newval1
]
1656 set smallhash
($k) newval1
1657 lappend rv
[$r hget smallhash
$k]
1658 lappend rv
[$r hset smallhash __foobar123__ newval
]
1659 set k
[lindex [array names bighash
*] 0]
1660 lappend rv
[$r hset bighash
$k newval2
]
1661 set bighash
($k) newval2
1662 lappend rv
[$r hget bighash
$k]
1663 lappend rv
[$r hset bighash __foobar123__ newval
]
1664 lappend rv
[$r hdel smallhash __foobar123__
]
1665 lappend rv
[$r hdel bighash __foobar123__
]
1667 } {0 newval1
1 0 newval2
1 1 1}
1669 test
{HSETNX target key missing
- small hash
} {
1670 $r hsetnx smallhash __123123123__ foo
1671 $r hget smallhash __123123123__
1674 test
{HSETNX target key exists
- small hash
} {
1675 $r hsetnx smallhash __123123123__ bar
1676 set result
[$r hget smallhash __123123123__
]
1677 $r hdel smallhash __123123123__
1681 test
{HSETNX target key missing
- big hash
} {
1682 $r hsetnx bighash __123123123__ foo
1683 $r hget bighash __123123123__
1686 test
{HSETNX target key exists
- big hash
} {
1687 $r hsetnx bighash __123123123__ bar
1688 set result
[$r hget bighash __123123123__
]
1689 $r hdel bighash __123123123__
1693 test
{HMSET wrong number of args
} {
1694 catch {$r hmset smallhash key1 val1 key2
} err
1698 test
{HMSET
- small hash
} {
1700 foreach {k v
} [array get smallhash
] {
1701 set newval
[randstring
0 8 alpha
]
1702 set smallhash
($k) $newval
1703 lappend args
$k $newval
1705 $r hmset smallhash
{*}$args
1708 test
{HMSET
- big hash
} {
1710 foreach {k v
} [array get bighash
] {
1711 set newval
[randstring
0 8 alpha
]
1712 set bighash
($k) $newval
1713 lappend args
$k $newval
1715 $r hmset bighash
{*}$args
1718 test
{HMGET against non existing key and fields
} {
1720 lappend rv
[$r hmget doesntexist __123123123__ __456456456__
]
1721 lappend rv
[$r hmget smallhash __123123123__ __456456456__
]
1722 lappend rv
[$r hmget bighash __123123123__ __456456456__
]
1724 } {{{} {}} {{} {}} {{} {}}}
1726 test
{HMGET
- small hash
} {
1729 foreach {k v
} [array get smallhash
] {
1734 set result
[$r hmget smallhash
{*}$keys]
1735 if {$vals ne
$result} {
1736 set err
"$vals != $result"
1742 test
{HMGET
- big hash
} {
1745 foreach {k v
} [array get bighash
] {
1750 set result
[$r hmget bighash
{*}$keys]
1751 if {$vals ne
$result} {
1752 set err
"$vals != $result"
1758 test
{HKEYS
- small hash
} {
1759 lsort [$r hkeys smallhash
]
1760 } [lsort [array names smallhash
*]]
1762 test
{HKEYS
- big hash
} {
1763 lsort [$r hkeys bighash
]
1764 } [lsort [array names bighash
*]]
1766 test
{HVALS
- small hash
} {
1768 foreach {k v
} [array get smallhash
] {
1772 } [lsort [$r hvals smallhash
]]
1774 test
{HVALS
- big hash
} {
1776 foreach {k v
} [array get bighash
] {
1780 } [lsort [$r hvals bighash
]]
1782 test
{HGETALL
- small hash
} {
1783 lsort [$r hgetall smallhash
]
1784 } [lsort [array get smallhash
]]
1786 test
{HGETALL
- big hash
} {
1787 lsort [$r hgetall bighash
]
1788 } [lsort [array get bighash
]]
1790 test
{HDEL and
return value
} {
1792 lappend rv
[$r hdel smallhash nokey
]
1793 lappend rv
[$r hdel bighash nokey
]
1794 set k
[lindex [array names smallhash
*] 0]
1795 lappend rv
[$r hdel smallhash
$k]
1796 lappend rv
[$r hdel smallhash
$k]
1797 lappend rv
[$r hget smallhash
$k]
1799 set k
[lindex [array names bighash
*] 0]
1800 lappend rv
[$r hdel bighash
$k]
1801 lappend rv
[$r hdel bighash
$k]
1802 lappend rv
[$r hget bighash
$k]
1805 } {0 0 1 0 {} 1 0 {}}
1809 set k
[lindex [array names smallhash
*] 0]
1810 lappend rv
[$r hexists smallhash
$k]
1811 lappend rv
[$r hexists smallhash nokey
]
1812 set k
[lindex [array names bighash
*] 0]
1813 lappend rv
[$r hexists bighash
$k]
1814 lappend rv
[$r hexists bighash nokey
]
1817 test
{Is a zipmap encoded Hash promoted on big payload?
} {
1818 $r hset smallhash foo
[string repeat a
1024]
1819 $r debug object smallhash
1822 test
{HINCRBY against non existing database key
} {
1824 list [$r hincrby htest foo
2]
1827 test
{HINCRBY against non existing hash key
} {
1829 $r hdel smallhash tmp
1831 lappend rv
[$r hincrby smallhash tmp
2]
1832 lappend rv
[$r hget smallhash tmp
]
1833 lappend rv
[$r hincrby bighash tmp
2]
1834 lappend rv
[$r hget bighash tmp
]
1837 test
{HINCRBY against hash key created by hincrby itself
} {
1839 lappend rv
[$r hincrby smallhash tmp
3]
1840 lappend rv
[$r hget smallhash tmp
]
1841 lappend rv
[$r hincrby bighash tmp
3]
1842 lappend rv
[$r hget bighash tmp
]
1845 test
{HINCRBY against hash key originally
set with HSET
} {
1846 $r hset smallhash tmp
100
1847 $r hset bighash tmp
100
1848 list [$r hincrby smallhash tmp
2] [$r hincrby bighash tmp
2]
1851 test
{HINCRBY over
32bit value
} {
1852 $r hset smallhash tmp
17179869184
1853 $r hset bighash tmp
17179869184
1854 list [$r hincrby smallhash tmp
1] [$r hincrby bighash tmp
1]
1855 } {17179869185 17179869185}
1857 test
{HINCRBY over
32bit value with over
32bit increment
} {
1858 $r hset smallhash tmp
17179869184
1859 $r hset bighash tmp
17179869184
1860 list [$r hincrby smallhash tmp
17179869184] [$r hincrby bighash tmp
17179869184]
1861 } {34359738368 34359738368}
1863 test
{HINCRBY fails against hash value with spaces
} {
1864 $r hset smallhash str
" 11 "
1865 $r hset bighash str
" 11 "
1866 catch {$r hincrby smallhash str
1} smallerr
1867 catch {$r hincrby smallhash str
1} bigerr
1869 lappend rv
[string match
"ERR*not an integer*" $smallerr]
1870 lappend rv
[string match
"ERR*not an integer*" $bigerr]
1874 # Randomized test, small and big
1875 # .rdb / AOF consistency test should include hashes
1877 test
{EXPIRE
- don't
set timeouts multiple times
} {
1879 set v1
[$r expire x
5]
1881 set v3
[$r expire x
10]
1883 list $v1 $v2 $v3 $v4
1886 test
{EXPIRE
- It should be still possible to
read 'x'
} {
1890 test
{EXPIRE
- After
6 seconds the key should no longer be here
} {
1892 list [$r get x
] [$r exists x
]
1895 test
{EXPIRE
- Delete on write policy
} {
1903 test
{EXPIREAT
- Check
for EXPIRE alike behavior
} {
1906 $r expireat x
[expr [clock seconds
]+15]
1910 test
{SETEX
- Set
+ Expire combo operation. Check
for TTL
} {
1915 test
{SETEX
- Check value
} {
1919 test
{SETEX
- Overwrite old key
} {
1924 test
{SETEX
- Wait
for the key to expire
} {
1929 test
{SETEX
- Wrong
time parameter
} {
1930 catch {$r setex z
-10 foo
} e
1932 } {*invalid expire
*}
1934 test
{ZSETs skiplist implementation backlink consistency test
} {
1937 for {set j
0} {$j < $elements} {incr j
} {
1938 $r zadd myzset
[expr rand
()] "Element-$j"
1939 $r zrem myzset
"Element-[expr int(rand()*$elements)]"
1941 set l1
[$r zrange myzset
0 -1]
1942 set l2
[$r zrevrange myzset
0 -1]
1943 for {set j
0} {$j < [llength $l1]} {incr j
} {
1944 if {[lindex $l1 $j] ne
[lindex $l2 end-
$j]} {
1951 test
{ZSETs ZRANK augmented skip
list stress testing
} {
1954 for {set k
0} {$k < 10000} {incr k
} {
1955 set i
[expr {$k%1000}]
1956 if {[expr rand
()] < .2} {
1959 set score
[expr rand
()]
1960 $r zadd myzset
$score $i
1962 set card
[$r zcard myzset
]
1964 set index
[randomInt
$card]
1965 set ele
[lindex [$r zrange myzset
$index $index] 0]
1966 set rank
[$r zrank myzset
$ele]
1967 if {$rank != $index} {
1968 set err
"$ele RANK is wrong! ($rank != $index)"
1976 foreach fuzztype
{binary alpha compr
} {
1977 test
"FUZZ stresser with data model $fuzztype" {
1979 for {set i
0} {$i < 10000} {incr i
} {
1980 set fuzz
[randstring
0 512 $fuzztype]
1982 set got
[$r get foo
]
1983 if {$got ne
$fuzz} {
1984 set err
[list $fuzz $got]
2003 test
{Handle an empty query well
} {
2005 puts -nonewline $fd "\r\n"
2010 test
{Negative multi bulk command does not create problems
} {
2012 puts -nonewline $fd "*-10\r\n"
2017 test
{Negative multi bulk payload
} {
2019 puts -nonewline $fd "SET x -10\r\n"
2024 test
{Too big bulk payload
} {
2026 puts -nonewline $fd "SET x 2000000000\r\n"
2029 } {*invalid bulk
*count
*}
2031 test
{Multi bulk request not followed by bulk args
} {
2033 puts -nonewline $fd "*1\r\nfoo\r\n"
2036 } {*protocol
error*}
2038 test
{Generic wrong number of args
} {
2039 catch {$r ping x y z
} err
2041 } {*wrong
*arguments
*ping
*}
2043 test
{SELECT an out of range DB
} {
2044 catch {$r select
1000000} err
2048 if {![catch {package require sha1
}]} {
2049 test
{Check consistency of different data types
after a reload
} {
2051 createComplexDataset
$r 10000
2052 set sha1
[datasetDigest
$r]
2054 set sha1_after
[datasetDigest
$r]
2055 expr {$sha1 eq
$sha1_after}
2058 test
{Same dataset digest
if saving
/reloading as AOF?
} {
2060 waitForBgrewriteaof
$r
2062 set sha1_after
[datasetDigest
$r]
2063 expr {$sha1 eq
$sha1_after}
2067 test
{EXPIRES
after a reload
(snapshot
+ append only
file)} {
2074 set e1
[expr {$ttl > 900 && $ttl <= 1000}]
2076 waitForBgrewriteaof
$r
2078 set e2
[expr {$ttl > 900 && $ttl <= 1000}]
2082 test
{PIPELINING stresser
(also a regression
for the old epoll bug
)} {
2083 set fd2
[socket $::host $::port]
2084 fconfigure $fd2 -encoding binary -translation binary
2085 puts -nonewline $fd2 "SELECT 9\r\n"
2089 for {set i
0} {$i < 100000} {incr i
} {
2091 set val
"0000${i}0000"
2092 append q
"SET key:$i [string length $val]\r\n$val\r\n"
2093 puts -nonewline $fd2 $q
2095 append q
"GET key:$i\r\n"
2096 puts -nonewline $fd2 $q
2100 for {set i
0} {$i < 100000} {incr i
} {
2103 set count
[string range
$count 1 end
]
2104 set val
[read $fd2 $count]
2111 test
{MUTLI
/ EXEC basics
} {
2117 set v1
[$r lrange mylist
0 -1]
2121 } {QUEUED QUEUED
{{a b c
} PONG
}}
2129 set v1
[$r del mylist
]
2131 set v3
[$r lrange mylist
0 -1]
2133 } {QUEUED OK
{a b c
}}
2135 test
{APPEND basics
} {
2136 list [$r append foo bar
] [$r get foo
] \
2137 [$r append foo
100] [$r get foo
]
2140 test
{APPEND basics
, integer encoded values
} {
2145 lappend res
[$r get foo
]
2148 lappend res
[$r get foo
]
2151 test
{APPEND fuzzing
} {
2153 foreach type
{binary alpha compr
} {
2156 for {set i
0} {$i < 1000} {incr i
} {
2157 set bin
[randstring
0 10 $type]
2161 if {$buf != [$r get x
]} {
2162 set err
"Expected '$buf' found '[$r get x]'"
2169 test
{SUBSTR basics
} {
2171 $r set foo
"Hello World"
2172 lappend res
[$r substr foo
0 3]
2173 lappend res
[$r substr foo
0 -1]
2174 lappend res
[$r substr foo
-4 -1]
2175 lappend res
[$r substr foo
5 3]
2176 lappend res
[$r substr foo
5 5000]
2177 lappend res
[$r substr foo
-5000 10000]
2179 } {Hell
{Hello World
} orld
{} { World
} {Hello World
}}
2181 test
{SUBSTR against integer encoded values
} {
2186 test
{SUBSTR fuzzing
} {
2188 for {set i
0} {$i < 1000} {incr i
} {
2189 set bin
[randstring
0 1024 binary]
2190 set _start
[set start
[randomInt
1500]]
2191 set _end
[set end
[randomInt
1500]]
2192 if {$_start < 0} {set _start
"end-[abs($_start)-1]"}
2193 if {$_end < 0} {set _end
"end-[abs($_end)-1]"}
2194 set s1
[string range
$bin $_start $_end]
2196 set s2
[$r substr bin
$start $end]
2198 set err
"String mismatch"
2205 # Leave the user with a clean DB before to exit
2210 lappend aux
[$r dbsize
]
2213 lappend aux
[$r dbsize
]
2216 test
{Perform a final SAVE to leave a clean DB on disk
} {
2221 if {[string match
{*Darwin
*} [exec uname
-a]]} {
2222 test
{Check
for memory leaks
} {
2223 exec leaks redis-server
2228 puts "\n[expr $::passed+$::failed] tests, $::passed passed, $::failed failed"
2229 if {$::failed > 0} {
2230 puts "\n*** WARNING!!! $::failed FAILED TESTS ***\n"
2235 set r
[redis
$::host $::port]
2239 set randkey
[expr int
(rand
()*10000)]
2240 set randval
[expr int
(rand
()*10000)]
2241 set randidx0
[expr int
(rand
()*10)]
2242 set randidx1
[expr int
(rand
()*10)]
2243 set cmd
[expr int
(rand
()*20)]
2245 if {$cmd == 0} {$r set $randkey $randval}
2246 if {$cmd == 1} {$r get
$randkey}
2247 if {$cmd == 2} {$r incr $randkey}
2248 if {$cmd == 3} {$r lpush
$randkey $randval}
2249 if {$cmd == 4} {$r rpop
$randkey}
2250 if {$cmd == 5} {$r del
$randkey}
2251 if {$cmd == 6} {$r llen
$randkey}
2252 if {$cmd == 7} {$r lrange $randkey $randidx0 $randidx1}
2253 if {$cmd == 8} {$r ltrim
$randkey $randidx0 $randidx1}
2254 if {$cmd == 9} {$r lindex $randkey $randidx0}
2255 if {$cmd == 10} {$r lset $randkey $randidx0 $randval}
2256 if {$cmd == 11} {$r sadd
$randkey $randval}
2257 if {$cmd == 12} {$r srem
$randkey $randval}
2258 if {$cmd == 13} {$r smove
$randkey $randval}
2259 if {$cmd == 14} {$r scard
$randkey}
2260 if {$cmd == 15} {$r expire
$randkey [expr $randval%60]}
2268 # Set a few configuration defaults
2269 set ::host 127.0.0.1
2278 for {set j
0} {$j < [llength $argv]} {incr j
} {
2279 set opt
[lindex $argv $j]
2280 set arg
[lindex $argv [expr $j+1]]
2281 set lastarg
[expr {$arg eq
{}}]
2282 if {$opt eq
{-h} && !$lastarg} {
2285 } elseif
{$opt eq
{-p} && !$lastarg} {
2288 } elseif
{$opt eq
{--stress}} {
2290 } elseif
{$opt eq
{--trace-leaks
}} {
2292 } elseif
{$opt eq
{--flush}} {
2294 } elseif
{$opt eq
{--first} && !$lastarg} {
2297 } elseif
{$opt eq
{--last} && !$lastarg} {
2301 puts "Wrong argument: $opt"
2306 # Before to run the test check if DB 9 and DB 10 are empty
2307 set r
[redis
$::host $::port]
2314 set db9size
[$r dbsize
]
2316 set db10size
[$r dbsize
]
2317 if {$db9size != 0 ||
$db10size != 0} {
2318 puts "Can't run the tests against DB 9 and 10: DBs are not empty."
2326 puts "Testing Redis, host $::host, port $::port"