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 main
{server port
} {
69 set r
[redis
$server $port]
74 # The following AUTH test should be enabled only when requirepass
75 # <PASSWORD> is set in redis.conf and redis-server was started with
76 # redis.conf as the first argument.
78 #test {AUTH with requirepass in redis.conf} {
82 test
{DEL all keys to start with a clean DB
} {
83 foreach key
[$r keys
*] {$r del
$key}
87 test
{SET and GET an item
} {
92 test
{DEL against a single item
} {
101 list [$r del foo1 foo2 foo3 foo4
] [$r mget foo1 foo2 foo3
]
104 test
{KEYS with pattern
} {
105 foreach key
{key_x key_y key_z foo_a foo_b foo_c
} {
109 } {foo_a foo_b foo_c
}
111 test
{KEYS to get all keys
} {
113 } {foo_a foo_b foo_c key_x key_y key_z
}
119 test
{DEL all keys
} {
120 foreach key
[$r keys
*] {$r del
$key}
124 test
{Very big payload in GET
/SET
} {
125 set buf
[string repeat
"abcd" 1000000]
128 } [string repeat
"abcd" 1000000]
130 test
{SET
10000 numeric keys and access all them in reverse order
} {
131 for {set x
0} {$x < 10000} {incr x
} {
135 for {set x
9999} {$x >= 0} {incr x
-1} {
141 test
{DBSIZE should be
10001 now
} {
145 test
{INCR against non existing key
} {
147 append res
[$r incr novar
]
148 append res
[$r get novar
]
151 test
{INCR against key created by
incr itself
} {
155 test
{INCR against key originally
set with SET
} {
160 test
{INCR over
32bit value
} {
161 $r set novar
17179869184
165 test
{INCRBY over
32bit value with over
32bit increment
} {
166 $r set novar
17179869184
167 $r incrby novar
17179869184
170 test
{DECRBY over
32bit value with over
32bit increment
, negative res
} {
171 $r set novar
17179869184
172 $r decrby novar
17179869185
175 test
{SETNX target key missing
} {
176 $r setnx novar2 foobared
180 test
{SETNX target key exists
} {
181 $r setnx novar2 blabla
185 test
{SETNX will overwrite EXPIREing key
} {
195 append res
[$r exists newkey
]
197 append res
[$r exists newkey
]
200 test
{Zero length value in key. SET
/GET
/EXISTS
} {
202 set res
[$r get emptykey
]
203 append res
[$r exists emptykey
]
205 append res
[$r exists emptykey
]
208 test
{Commands pipelining
} {
210 puts -nonewline $fd "SET k1 4\r\nxyzk\r\nGET k1\r\nPING\r\n"
213 append res
[string match OK
* [::redis::redis_read_reply $fd]]
214 append res
[::redis::redis_read_reply $fd]
215 append res
[string match PONG
* [::redis::redis_read_reply $fd]]
219 test
{Non existing command
} {
220 catch {$r foobaredcommand
} err
221 string match ERR
* $err
224 test
{Basic LPUSH
, RPUSH
, LLENGTH
, LINDEX
} {
228 set res
[$r llen mylist
]
229 append res
[$r lindex mylist
0]
230 append res
[$r lindex mylist
1]
231 append res
[$r lindex mylist
2]
239 test
{Create a long
list and check every single element with LINDEX
} {
241 for {set i
0} {$i < 1000} {incr i
} {
244 for {set i
0} {$i < 1000} {incr i
} {
245 if {[$r lindex mylist
$i] eq
$i} {incr ok
}
246 if {[$r lindex mylist
[expr (-$i)-1]] eq
[expr 999-$i]} {
253 test
{Test elements with LINDEX in random access
} {
255 for {set i
0} {$i < 1000} {incr i
} {
256 set rint
[expr int
(rand
()*1000)]
257 if {[$r lindex mylist
$rint] eq
$rint} {incr ok
}
258 if {[$r lindex mylist
[expr (-$rint)-1]] eq
[expr 999-$rint]} {
265 test
{Check
if the
list is still ok
after a DEBUG RELOAD
} {
268 for {set i
0} {$i < 1000} {incr i
} {
269 set rint
[expr int
(rand
()*1000)]
270 if {[$r lindex mylist
$rint] eq
$rint} {incr ok
}
271 if {[$r lindex mylist
[expr (-$rint)-1]] eq
[expr 999-$rint]} {
278 test
{LLEN against non-list value
error} {
281 catch {$r llen mylist
} err
285 test
{LINDEX against non-list value
error} {
286 catch {$r lindex mylist
0} err
290 test
{LPUSH against non-list value
error} {
291 catch {$r lpush mylist
0} err
295 test
{RPUSH against non-list value
error} {
296 catch {$r rpush mylist
0} err
300 test
{RPOPLPUSH base case
} {
306 set v1
[$r rpoplpush mylist newlist
]
307 set v2
[$r rpoplpush mylist newlist
]
308 set l1
[$r lrange mylist
0 -1]
309 set l2
[$r lrange newlist
0 -1]
313 test
{RPOPLPUSH with the same
list as src and dst
} {
318 set l1
[$r lrange mylist
0 -1]
319 set v
[$r rpoplpush mylist mylist
]
320 set l2
[$r lrange mylist
0 -1]
322 } {{a b c
} c
{c a b
}}
324 test
{RPOPLPUSH target
list already exists
} {
332 set v1
[$r rpoplpush mylist newlist
]
333 set v2
[$r rpoplpush mylist newlist
]
334 set l1
[$r lrange mylist
0 -1]
335 set l2
[$r lrange newlist
0 -1]
337 } {d c
{a b
} {c d x
}}
339 test
{RPOPLPUSH against non existing key
} {
342 set v1
[$r rpoplpush mylist newlist
]
343 list $v1 [$r exists mylist
] [$r exists newlist
]
346 test
{RPOPLPUSH against non
list src key
} {
350 catch {$r rpoplpush mylist newlist
} err
351 list [$r type mylist
] [$r exists newlist
] [string range
$err 0 2]
354 test
{RPOPLPUSH against non
list dst key
} {
362 catch {$r rpoplpush mylist newlist
} err
363 list [$r lrange mylist
0 -1] [$r type newlist
] [string range
$err 0 2]
364 } {{a b c d
} string ERR
}
366 test
{RENAME basic usage
} {
368 $r rename mykey mykey1
369 $r rename mykey1 mykey2
373 test
{RENAME
source key should no longer exist
} {
377 test
{RENAME against already existing key
} {
380 $r rename mykey2 mykey
381 set res
[$r get mykey
]
382 append res
[$r exists mykey2
]
385 test
{RENAMENX basic usage
} {
389 $r renamenx mykey mykey2
390 set res
[$r get mykey2
]
391 append res
[$r exists mykey
]
394 test
{RENAMENX against already existing key
} {
397 $r renamenx mykey mykey2
400 test
{RENAMENX against already existing key
(2)} {
401 set res
[$r get mykey
]
402 append res
[$r get mykey2
]
405 test
{RENAME against non existing
source key
} {
406 catch {$r rename nokey foobar
} err
410 test
{RENAME where
source and dest key is the same
} {
411 catch {$r rename mykey mykey
} err
415 test
{DEL all keys again
(DB
0)} {
416 foreach key
[$r keys
*] {
422 test
{DEL all keys again
(DB
1)} {
424 foreach key
[$r keys
*] {
432 test
{MOVE basic usage
} {
436 lappend res
[$r exists mykey
]
437 lappend res
[$r dbsize
]
439 lappend res
[$r get mykey
]
440 lappend res
[$r dbsize
]
443 } [list 0 0 foobar
1]
445 test
{MOVE against key existing in the target DB
} {
450 test
{SET
/GET keys in different DBs
} {
458 lappend res
[$r get a
]
459 lappend res
[$r get b
]
461 lappend res
[$r get a
]
462 lappend res
[$r get b
]
465 } {hello world foo bared
}
467 test
{Basic LPOP
/RPOP
} {
472 list [$r lpop mylist
] [$r rpop mylist
] [$r lpop mylist
] [$r llen mylist
]
475 test
{LPOP
/RPOP against empty
list} {
479 test
{LPOP against non
list value
} {
481 catch {$r lpop notalist
} err
485 test
{Mass LPUSH
/LPOP
} {
487 for {set i
0} {$i < 1000} {incr i
} {
492 for {set i
0} {$i < 500} {incr i
} {
493 incr sum2
[$r lpop mylist
]
494 incr sum2
[$r rpop mylist
]
499 test
{LRANGE basics
} {
500 for {set i
0} {$i < 10} {incr i
} {
503 list [$r lrange mylist
1 -2] \
504 [$r lrange mylist
-3 -1] \
505 [$r lrange mylist
4 4]
506 } {{1 2 3 4 5 6 7 8} {7 8 9} 4}
508 test
{LRANGE inverted indexes
} {
512 test
{LRANGE out of range indexes including the full
list} {
513 $r lrange mylist
-1000 1000
514 } {0 1 2 3 4 5 6 7 8 9}
516 test
{LRANGE against non existing key
} {
517 $r lrange nosuchkey
0 1
520 test
{LTRIM basics
} {
522 for {set i
0} {$i < 100} {incr i
} {
526 $r lrange mylist
0 -1
531 $r lset mylist
-1 bar
532 $r lrange mylist
0 -1
535 test
{LSET out of range index
} {
536 catch {$r lset mylist
10 foo
} err
540 test
{LSET against non existing key
} {
541 catch {$r lset nosuchkey
10 foo
} err
545 test
{LSET against non
list value
} {
547 catch {$r lset nolist
0 foo
} err
551 test
{SADD
, SCARD
, SISMEMBER
, SMEMBERS basics
} {
554 list [$r scard myset
] [$r sismember myset foo
] \
555 [$r sismember myset bar
] [$r sismember myset bla
] \
556 [lsort [$r smembers myset
]]
557 } {2 1 1 0 {bar foo
}}
559 test
{SADD adding the same element multiple times
} {
566 test
{SADD against non
set} {
567 catch {$r sadd mylist foo
} err
574 lsort [$r smembers myset
]
577 test
{Mass SADD and SINTER with two sets
} {
578 for {set i
0} {$i < 1000} {incr i
} {
580 $r sadd set2
[expr $i+995]
582 lsort [$r sinter set1 set2
]
583 } {995 996 997 998 999}
585 test
{SUNION with two sets
} {
586 lsort [$r sunion set1 set2
]
587 } [lsort -uniq "[$r smembers set1] [$r smembers set2]"]
589 test
{SINTERSTORE with two sets
} {
590 $r sinterstore setres set1 set2
591 lsort [$r smembers setres
]
592 } {995 996 997 998 999}
594 test
{SINTERSTORE with two sets
, after a DEBUG RELOAD
} {
596 $r sinterstore setres set1 set2
597 lsort [$r smembers setres
]
598 } {995 996 997 998 999}
600 test
{SUNIONSTORE with two sets
} {
601 $r sunionstore setres set1 set2
602 lsort [$r smembers setres
]
603 } [lsort -uniq "[$r smembers set1] [$r smembers set2]"]
605 test
{SUNIONSTORE against non existing keys
} {
607 list [$r sunionstore setres foo111 bar222
] [$r exists xxx
]
610 test
{SINTER against three sets
} {
615 lsort [$r sinter set1 set2 set3
]
618 test
{SINTERSTORE with three sets
} {
619 $r sinterstore setres set1 set2 set3
620 lsort [$r smembers setres
]
623 test
{SUNION with non existing keys
} {
624 lsort [$r sunion nokey1 set1 set2 nokey2
]
625 } [lsort -uniq "[$r smembers set1] [$r smembers set2]"]
627 test
{SDIFF with two sets
} {
628 for {set i
5} {$i < 1000} {incr i
} {
631 lsort [$r sdiff set1 set4
]
634 test
{SDIFF with three sets
} {
636 lsort [$r sdiff set1 set4 set5
]
639 test
{SDIFFSTORE with three sets
} {
640 $r sdiffstore sres set1 set4 set5
641 lsort [$r smembers sres
]
649 list [lsort [list [$r spop myset
] [$r spop myset
] [$r spop myset
]]] [$r scard myset
]
652 test
{SAVE
- make sure there are all the types as values
} {
653 # Wait for a background saving in progress to terminate
655 $r lpush mysavelist hello
656 $r lpush mysavelist world
658 $r set mynormalkey
{blablablba
}
659 $r zadd mytestzset a
10
660 $r zadd mytestzset b
20
661 $r zadd mytestzset c
30
670 unset -nocomplain myset
672 for {set i
0} {$i < 100} {incr i
} {
673 set myset
([$r srandmember myset
]) 1
675 lsort [array names myset
]
678 test
{Create a random
list} {
680 array set seenrand
{}
681 for {set i
0} {$i < 10000} {incr i
} {
683 # Make sure all the weights are different because
684 # Redis does not use a stable sort but Tcl does.
685 set rint
[expr int
(rand
()*1000000)]
686 if {![info exists seenrand
($rint)]} break
688 set seenrand
($rint) x
690 $r set weight_
$i $rint
691 lappend tosort
[list $i $rint]
693 set sorted
[lsort -index 1 -real $tosort]
695 for {set i
0} {$i < 10000} {incr i
} {
696 lappend res
[lindex $sorted $i 0]
701 test
{SORT with BY against the newly created
list} {
702 $r sort tosort
{BY weight_
*}
705 test
{SORT direct
, numeric
, against the newly created
list} {
707 } [lsort -integer $res]
709 test
{SORT decreasing sort
} {
710 $r sort tosort
{DESC
}
711 } [lsort -decreasing -integer $res]
713 test
{SORT speed
, sorting
10000 elements
list using BY
, 100 times
} {
714 set start
[clock clicks
-milliseconds]
715 for {set i
0} {$i < 100} {incr i
} {
716 set sorted
[$r sort tosort
{BY weight_
* LIMIT
0 10}]
718 set elapsed
[expr [clock clicks
-milliseconds]-$start]
719 puts -nonewline "\n Average time to sort: [expr double($elapsed)/100] milliseconds "
724 test
{SORT speed
, sorting
10000 elements
list directly
, 100 times
} {
725 set start
[clock clicks
-milliseconds]
726 for {set i
0} {$i < 100} {incr i
} {
727 set sorted
[$r sort tosort
{LIMIT
0 10}]
729 set elapsed
[expr [clock clicks
-milliseconds]-$start]
730 puts -nonewline "\n Average time to sort: [expr double($elapsed)/100] milliseconds "
735 test
{SORT speed
, pseudo-sorting
10000 elements
list, BY
<const
>, 100 times
} {
736 set start
[clock clicks
-milliseconds]
737 for {set i
0} {$i < 100} {incr i
} {
738 set sorted
[$r sort tosort
{BY nokey LIMIT
0 10}]
740 set elapsed
[expr [clock clicks
-milliseconds]-$start]
741 puts -nonewline "\n Average time to sort: [expr double($elapsed)/100] milliseconds "
746 test
{SORT regression
for issue
#19, sorting floats} {
748 foreach x
{1.1 5.10 3.10 7.44 2.1 5.75 6.12 0.25 1.15} {
752 } [lsort -real {1.1 5.10 3.10 7.44 2.1 5.75 6.12 0.25 1.15}]
754 test
{SORT with GET
#} {
759 $r mset weight_1
10 weight_2
5 weight_3
30
760 $r sort mylist BY weight_
* GET
#
763 test
{LREM
, remove all the occurrences
} {
767 $r rpush mylist foobar
768 $r rpush mylist foobared
773 set res
[$r lrem mylist
0 bar
]
774 list [$r lrange mylist
0 -1] $res
775 } {{foo foobar foobared zap test foo
} 2}
777 test
{LREM
, remove the first occurrence
} {
778 set res
[$r lrem mylist
1 foo
]
779 list [$r lrange mylist
0 -1] $res
780 } {{foobar foobared zap test foo
} 1}
782 test
{LREM
, remove non existing element
} {
783 set res
[$r lrem mylist
1 nosuchelement
]
784 list [$r lrange mylist
0 -1] $res
785 } {{foobar foobared zap test foo
} 0}
787 test
{LREM
, starting from tail with negative count
} {
791 $r rpush mylist foobar
792 $r rpush mylist foobared
798 set res
[$r lrem mylist
-1 bar
]
799 list [$r lrange mylist
0 -1] $res
800 } {{foo bar foobar foobared zap test foo foo
} 1}
802 test
{LREM
, starting from tail with negative count
(2)} {
803 set res
[$r lrem mylist
-2 foo
]
804 list [$r lrange mylist
0 -1] $res
805 } {{foo bar foobar foobared zap test
} 2}
807 test
{LREM
, deleting objects that may be encoded as integers
} {
808 $r lpush myotherlist
1
809 $r lpush myotherlist
2
810 $r lpush myotherlist
3
811 $r lrem myotherlist
1 2
822 test
{MGET against non existing key
} {
823 $r mget foo baazz bar
826 test
{MGET against non-string key
} {
829 $r mget foo baazz bar myset
838 for {set i
0} {$i < 100} {incr i
} {
839 set rkey
[$r randomkey
]
840 if {$rkey eq
{foo
}} {
843 if {$rkey eq
{bar
}} {
847 list $foo_seen $bar_seen
850 test
{RANDOMKEY against empty DB
} {
855 test
{RANDOMKEY regression
1} {
862 test
{GETSET
(set new value
)} {
863 list [$r getset foo xyz
] [$r get foo
]
866 test
{GETSET
(replace old value
)} {
868 list [$r getset foo xyz
] [$r get foo
]
871 test
{SMOVE basics
} {
878 $r smove myset1 myset2 a
879 list [lsort [$r smembers myset2
]] [lsort [$r smembers myset1
]]
882 test
{SMOVE non existing key
} {
883 list [$r smove myset1 myset2 foo
] [lsort [$r smembers myset2
]] [lsort [$r smembers myset1
]]
884 } {0 {a x y z
} {b c
}}
886 test
{SMOVE non existing src
set} {
887 list [$r smove noset myset2 foo
] [lsort [$r smembers myset2
]]
890 test
{SMOVE non existing dst
set} {
891 list [$r smove myset2 myset3 y
] [lsort [$r smembers myset2
]] [lsort [$r smembers myset3
]]
894 test
{SMOVE wrong src key type
} {
896 catch {$r smove x myset2 foo
} err
900 test
{SMOVE wrong dst key type
} {
902 catch {$r smove myset2 x foo
} err
906 test
{MSET base case
} {
907 $r mset x
10 y
"foo bar" z
"x x x x x x x\n\n\r\n"
909 } [list 10 {foo bar
} "x x x x x x x\n\n\r\n"]
911 test
{MSET wrong number of args
} {
912 catch {$r mset x
10 y
"foo bar" z
} err
916 test
{MSETNX with already existent key
} {
917 list [$r msetnx x1 xxx y2 yyy x
20] [$r exists x1
] [$r exists y2
]
920 test
{MSETNX with not existing keys
} {
921 list [$r msetnx x1 xxx y2 yyy
] [$r get x1
] [$r get y2
]
924 test
{MSETNX should remove all the volatile keys even on
failure} {
928 list [$r msetnx x A y B z C
] [$r mget x y z
]
931 test
{ZSET basic ZADD and score
update} {
935 set aux1
[$r zrange ztmp
0 -1]
937 set aux2
[$r zrange ztmp
0 -1]
941 test
{ZCARD basics
} {
945 test
{ZCARD non existing key
} {
952 for {set i
0} {$i < 1000} {incr i
} {
953 set score
[expr rand
()]
955 $r zadd zscoretest
$score $i
957 for {set i
0} {$i < 1000} {incr i
} {
958 if {[$r zscore zscoretest
$i] != [lindex $aux $i]} {
959 set err
"Expected score was [lindex $aux $i] but got [$r zscore zscoretest $i] for element $i"
966 test
{ZSCORE
after a DEBUG RELOAD
} {
970 for {set i
0} {$i < 1000} {incr i
} {
971 set score
[expr rand
()]
973 $r zadd zscoretest
$score $i
976 for {set i
0} {$i < 1000} {incr i
} {
977 if {[$r zscore zscoretest
$i] != [lindex $aux $i]} {
978 set err
"Expected score was [lindex $aux $i] but got [$r zscore zscoretest $i] for element $i"
985 test
{ZRANGE and ZREVRANGE
} {
986 list [$r zrange ztmp
0 -1] [$r zrevrange ztmp
0 -1]
989 test
{ZSETs stress tester
- sorting is working well?
} {
991 for {set test
0} {$test < 2} {incr test
} {
992 unset -nocomplain auxarray
993 array set auxarray
{}
996 for {set i
0} {$i < 1000} {incr i
} {
998 set score
[expr rand
()]
1000 set score
[expr int
(rand
()*10)]
1002 set auxarray
($i) $score
1003 $r zadd myzset
$score $i
1005 if {[expr rand
()] < .2} {
1006 set j
[expr int
(rand
()*1000)]
1008 set score
[expr rand
()]
1010 set score
[expr int
(rand
()*10)]
1012 set auxarray
($j) $score
1013 $r zadd myzset
$score $j
1016 foreach {item score
} [array get auxarray
] {
1017 lappend auxlist
[list $score $item]
1019 set sorted
[lsort -command zlistAlikeSort
$auxlist]
1022 lappend auxlist
[lindex $x 1]
1024 set fromredis
[$r zrange myzset
0 -1]
1026 for {set i
0} {$i < [llength $fromredis]} {incr i
} {
1027 if {[lindex $fromredis $i] != [lindex $auxlist $i]} {
1035 test
{ZINCRBY
- can create a new sorted
set} {
1037 $r zincrby zset
1 foo
1038 list [$r zrange zset
0 -1] [$r zscore zset foo
]
1041 test
{ZINCRBY
- increment and decrement
} {
1042 $r zincrby zset
2 foo
1043 $r zincrby zset
1 bar
1044 set v1
[$r zrange zset
0 -1]
1045 $r zincrby zset
10 bar
1046 $r zincrby zset
-5 foo
1047 $r zincrby zset
-5 bar
1048 set v2
[$r zrange zset
0 -1]
1049 list $v1 $v2 [$r zscore zset foo
] [$r zscore zset bar
]
1050 } {{bar foo
} {foo bar
} -2 6}
1052 test
{ZRANGEBYSCORE basics
} {
1059 $r zrangebyscore zset
2 4
1062 test
{ZRANGEBYSCORE fuzzy test
, 100 ranges in
1000 elements sorted
set} {
1065 for {set i
0} {$i < 1000} {incr i
} {
1066 $r zadd zset
[expr rand
()] $i
1068 for {set i
0} {$i < 100} {incr i
} {
1069 set min
[expr rand
()]
1070 set max
[expr rand
()]
1076 set low
[$r zrangebyscore zset
-inf $min]
1077 set ok
[$r zrangebyscore zset
$min $max]
1078 set high
[$r zrangebyscore zset
$max +inf
]
1080 set score
[$r zscore zset
$x]
1081 if {$score > $min} {
1082 append err
"Error, score for $x is $score > $min\n"
1086 set score
[$r zscore zset
$x]
1087 if {$score < $min ||
$score > $max} {
1088 append err
"Error, score for $x is $score outside $min-$max range\n"
1092 set score
[$r zscore zset
$x]
1093 if {$score < $max} {
1094 append err
"Error, score for $x is $score < $max\n"
1101 test
{ZRANGEBYSCORE with LIMIT
} {
1109 [$r zrangebyscore zset
0 10 LIMIT
0 2] \
1110 [$r zrangebyscore zset
0 10 LIMIT
2 3] \
1111 [$r zrangebyscore zset
0 10 LIMIT
2 10] \
1112 [$r zrangebyscore zset
0 10 LIMIT
20 10]
1113 } {{a b
} {c d e
} {c d e
} {}}
1115 test
{ZREMRANGE basics
} {
1122 list [$r zremrangebyscore zset
2 4] [$r zrange zset
0 -1]
1125 test
{ZREMRANGE from
-inf to
+inf
} {
1132 list [$r zremrangebyscore zset
-inf +inf
] [$r zrange zset
0 -1]
1135 test
{SORT against sorted sets
} {
1142 $r sort zset alpha desc
1145 test
{Sorted sets
+inf and
-inf handling
} {
1150 $r zadd zset
1000000 d
1151 $r zadd zset
+inf max
1152 $r zadd zset
-inf min
1156 test
{EXPIRE
- don't
set timeouts multiple times
} {
1158 set v1
[$r expire x
5]
1160 set v3
[$r expire x
10]
1162 list $v1 $v2 $v3 $v4
1165 test
{EXPIRE
- It should be still possible to
read 'x'
} {
1169 test
{EXPIRE
- After
6 seconds the key should no longer be here
} {
1171 list [$r get x
] [$r exists x
]
1174 test
{EXPIRE
- Delete on write policy
} {
1182 test
{EXPIREAT
- Check
for EXPIRE alike behavior
} {
1185 $r expireat x
[expr [clock seconds
]+15]
1189 test
{ZSETs skiplist implementation backlink consistency test
} {
1192 for {set j
0} {$j < $elements} {incr j
} {
1193 $r zadd myzset
[expr rand
()] "Element-$j"
1194 $r zrem myzset
"Element-[expr int(rand()*$elements)]"
1196 set l1
[$r zrange myzset
0 -1]
1197 set l2
[$r zrevrange myzset
0 -1]
1198 for {set j
0} {$j < [llength $l1]} {incr j
} {
1199 if {[lindex $l1 $j] ne
[lindex $l2 end-
$j]} {
1206 foreach fuzztype
{binary alpha compr
} {
1207 test
"FUZZ stresser with data model $fuzztype" {
1209 for {set i
0} {$i < 10000} {incr i
} {
1210 set fuzz
[randstring
0 512 $fuzztype]
1212 set got
[$r get foo
]
1213 if {$got ne
$fuzz} {
1214 set err
[list $fuzz $got]
1232 # Leave the user with a clean DB before to exit
1237 lappend aux
[$r dbsize
]
1240 lappend aux
[$r dbsize
]
1243 test
{Perform a final SAVE to leave a clean DB on disk
} {
1248 if {[string match
{*Darwin
*} [exec uname
-a]]} {
1249 test
{Check
for memory leaks
} {
1250 exec leaks redis-server
1255 puts "\n[expr $::passed+$::failed] tests, $::passed passed, $::failed failed"
1256 if {$::failed > 0} {
1257 puts "\n*** WARNING!!! $::failed FAILED TESTS ***\n"
1266 set randkey
[expr int
(rand
()*10000)]
1267 set randval
[expr int
(rand
()*10000)]
1268 set randidx0
[expr int
(rand
()*10)]
1269 set randidx1
[expr int
(rand
()*10)]
1270 set cmd
[expr int
(rand
()*20)]
1272 if {$cmd == 0} {$r set $randkey $randval}
1273 if {$cmd == 1} {$r get
$randkey}
1274 if {$cmd == 2} {$r incr $randkey}
1275 if {$cmd == 3} {$r lpush
$randkey $randval}
1276 if {$cmd == 4} {$r rpop
$randkey}
1277 if {$cmd == 5} {$r del
$randkey}
1278 if {$cmd == 6} {$r llen
$randkey}
1279 if {$cmd == 7} {$r lrange $randkey $randidx0 $randidx1}
1280 if {$cmd == 8} {$r ltrim
$randkey $randidx0 $randidx1}
1281 if {$cmd == 9} {$r lindex $randkey $randidx0}
1282 if {$cmd == 10} {$r lset $randkey $randidx0 $randval}
1283 if {$cmd == 11} {$r sadd
$randkey $randval}
1284 if {$cmd == 12} {$r srem
$randkey $randval}
1285 if {$cmd == 13} {$r smove
$randkey $randval}
1286 if {$cmd == 14} {$r scard
$randkey}
1287 if {$cmd == 15} {$r expire
$randkey [expr $randval%60]}
1295 # Set a few configuration defaults
1296 set ::host 127.0.0.1
1304 for {set j
0} {$j < [llength $argv]} {incr j
} {
1305 set opt
[lindex $argv $j]
1306 set arg
[lindex $argv [expr $j+1]]
1307 set lastarg
[expr {$arg eq
{}}]
1308 if {$opt eq
{-h} && !$lastarg} {
1311 } elseif
{$opt eq
{-p} && !$lastarg} {
1314 } elseif
{$opt eq
{-stress}} {
1316 } elseif
{$opt eq
{--flush}} {
1318 } elseif
{$opt eq
{--first} && !$lastarg} {
1321 } elseif
{$opt eq
{--last} && !$lastarg} {
1325 echo
"Wrong argument: $opt"
1330 # Before to run the test check if DB 9 and DB 10 are empty
1338 set db9size
[$r dbsize
]
1340 set db10size
[$r dbsize
]
1341 if {$db9size != 0 ||
$db10size != 0} {
1342 puts "Can't run the tests against DB 9 and 10: DBs are not empty."
1353 main
$::host $::port