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
12 proc test
{name code okpattern
} {
13 puts -nonewline [format "%-70s " $name]
15 set retval
[uplevel 1 $code]
16 if {$okpattern eq
$retval ||
[string match
$okpattern $retval]} {
20 puts "!! ERROR expected\n'$okpattern'\nbut got\n'$retval'"
25 proc randstring
{min max
{type
binary}} {
26 set len
[expr {$min+int
(rand
()*($max-$min+1))}]
28 if {$type eq
{binary}} {
31 } elseif
{$type eq
{alpha
}} {
34 } elseif
{$type eq
{compr
}} {
39 append output
[format "%c" [expr {$minval+int
(rand
()*($maxval-$minval+1))}]]
45 # Useful for some test
46 proc zlistAlikeSort
{a b
} {
47 if {[lindex $a 0] > [lindex $b 0]} {return 1}
48 if {[lindex $a 0] < [lindex $b 0]} {return -1}
49 string compare
[lindex $a 1] [lindex $b 1]
52 proc main
{server port
} {
53 set r
[redis
$server $port]
57 # The following AUTH test should be enabled only when requirepass
58 # <PASSWORD> is set in redis.conf and redis-server was started with
59 # redis.conf as the first argument.
61 #test {AUTH with requirepass in redis.conf} {
65 test
{DEL all keys to start with a clean DB
} {
66 foreach key
[$r keys
*] {$r del
$key}
70 test
{SET and GET an item
} {
75 test
{DEL against a single item
} {
84 list [$r del foo1 foo2 foo3 foo4
] [$r mget foo1 foo2 foo3
]
87 test
{KEYS with pattern
} {
88 foreach key
{key_x key_y key_z foo_a foo_b foo_c
} {
94 test
{KEYS to get all keys
} {
96 } {foo_a foo_b foo_c key_x key_y key_z
}
102 test
{DEL all keys
} {
103 foreach key
[$r keys
*] {$r del
$key}
107 test
{Very big payload in GET
/SET
} {
108 set buf
[string repeat
"abcd" 1000000]
111 } [string repeat
"abcd" 1000000]
113 test
{SET
10000 numeric keys and access all them in reverse order
} {
114 for {set x
0} {$x < 10000} {incr x
} {
118 for {set x
9999} {$x >= 0} {incr x
-1} {
124 test
{DBSIZE should be
10001 now
} {
128 test
{INCR against non existing key
} {
130 append res
[$r incr novar
]
131 append res
[$r get novar
]
134 test
{INCR against key created by
incr itself
} {
138 test
{INCR against key originally
set with SET
} {
143 test
{INCR over
32bit value
} {
144 $r set novar
17179869184
148 test
{INCRBY over
32bit value with over
32bit increment
} {
149 $r set novar
17179869184
150 $r incrby novar
17179869184
153 test
{DECRBY over
32bit value with over
32bit increment
, negative res
} {
154 $r set novar
17179869184
155 $r decrby novar
17179869185
158 test
{SETNX target key missing
} {
159 $r setnx novar2 foobared
163 test
{SETNX target key exists
} {
164 $r setnx novar2 blabla
171 append res
[$r exists newkey
]
173 append res
[$r exists newkey
]
176 test
{Zero length value in key. SET
/GET
/EXISTS
} {
178 set res
[$r get emptykey
]
179 append res
[$r exists emptykey
]
181 append res
[$r exists emptykey
]
184 test
{Commands pipelining
} {
186 puts -nonewline $fd "SET k1 4\r\nxyzk\r\nGET k1\r\nPING\r\n"
189 append res
[string match OK
* [::redis::redis_read_reply $fd]]
190 append res
[::redis::redis_read_reply $fd]
191 append res
[string match PONG
* [::redis::redis_read_reply $fd]]
195 test
{Non existing command
} {
196 catch {$r foobaredcommand
} err
197 string match ERR
* $err
200 test
{Basic LPUSH
, RPUSH
, LLENGTH
, LINDEX
} {
204 set res
[$r llen mylist
]
205 append res
[$r lindex mylist
0]
206 append res
[$r lindex mylist
1]
207 append res
[$r lindex mylist
2]
215 test
{Create a long
list and check every single element with LINDEX
} {
217 for {set i
0} {$i < 1000} {incr i
} {
220 for {set i
0} {$i < 1000} {incr i
} {
221 if {[$r lindex mylist
$i] eq
$i} {incr ok
}
222 if {[$r lindex mylist
[expr (-$i)-1]] eq
[expr 999-$i]} {
229 test
{Test elements with LINDEX in random access
} {
231 for {set i
0} {$i < 1000} {incr i
} {
232 set rint
[expr int
(rand
()*1000)]
233 if {[$r lindex mylist
$rint] eq
$rint} {incr ok
}
234 if {[$r lindex mylist
[expr (-$rint)-1]] eq
[expr 999-$rint]} {
241 test
{Check
if the
list is still ok
after a DEBUG RELOAD
} {
244 for {set i
0} {$i < 1000} {incr i
} {
245 set rint
[expr int
(rand
()*1000)]
246 if {[$r lindex mylist
$rint] eq
$rint} {incr ok
}
247 if {[$r lindex mylist
[expr (-$rint)-1]] eq
[expr 999-$rint]} {
254 test
{LLEN against non-list value
error} {
257 catch {$r llen mylist
} err
261 test
{LINDEX against non-list value
error} {
262 catch {$r lindex mylist
0} err
266 test
{LPUSH against non-list value
error} {
267 catch {$r lpush mylist
0} err
271 test
{RPUSH against non-list value
error} {
272 catch {$r rpush mylist
0} err
276 test
{RPOPLPUSH base case
} {
282 set v1
[$r rpoplpush mylist newlist
]
283 set v2
[$r rpoplpush mylist newlist
]
284 set l1
[$r lrange mylist
0 -1]
285 set l2
[$r lrange newlist
0 -1]
289 test
{RPOPLPUSH with the same
list as src and dst
} {
294 set l1
[$r lrange mylist
0 -1]
295 set v
[$r rpoplpush mylist mylist
]
296 set l2
[$r lrange mylist
0 -1]
298 } {{a b c
} c
{c a b
}}
300 test
{RPOPLPUSH target
list already exists
} {
308 set v1
[$r rpoplpush mylist newlist
]
309 set v2
[$r rpoplpush mylist newlist
]
310 set l1
[$r lrange mylist
0 -1]
311 set l2
[$r lrange newlist
0 -1]
313 } {d c
{a b
} {c d x
}}
315 test
{RPOPLPUSH against non existing key
} {
318 set v1
[$r rpoplpush mylist newlist
]
319 list $v1 [$r exists mylist
] [$r exists newlist
]
322 test
{RPOPLPUSH against non
list src key
} {
326 catch {$r rpoplpush mylist newlist
} err
327 list [$r type mylist
] [$r exists newlist
] [string range
$err 0 2]
330 test
{RPOPLPUSH against non
list dst key
} {
338 catch {$r rpoplpush mylist newlist
} err
339 list [$r lrange mylist
0 -1] [$r type newlist
] [string range
$err 0 2]
340 } {{a b c d
} string ERR
}
342 test
{RENAME basic usage
} {
344 $r rename mykey mykey1
345 $r rename mykey1 mykey2
349 test
{RENAME
source key should no longer exist
} {
353 test
{RENAME against already existing key
} {
356 $r rename mykey2 mykey
357 set res
[$r get mykey
]
358 append res
[$r exists mykey2
]
361 test
{RENAMENX basic usage
} {
365 $r renamenx mykey mykey2
366 set res
[$r get mykey2
]
367 append res
[$r exists mykey
]
370 test
{RENAMENX against already existing key
} {
373 $r renamenx mykey mykey2
376 test
{RENAMENX against already existing key
(2)} {
377 set res
[$r get mykey
]
378 append res
[$r get mykey2
]
381 test
{RENAME against non existing
source key
} {
382 catch {$r rename nokey foobar
} err
386 test
{RENAME where
source and dest key is the same
} {
387 catch {$r rename mykey mykey
} err
391 test
{DEL all keys again
(DB
0)} {
392 foreach key
[$r keys
*] {
398 test
{DEL all keys again
(DB
1)} {
400 foreach key
[$r keys
*] {
408 test
{MOVE basic usage
} {
412 lappend res
[$r exists mykey
]
413 lappend res
[$r dbsize
]
415 lappend res
[$r get mykey
]
416 lappend res
[$r dbsize
]
419 } [list 0 0 foobar
1]
421 test
{MOVE against key existing in the target DB
} {
426 test
{SET
/GET keys in different DBs
} {
434 lappend res
[$r get a
]
435 lappend res
[$r get b
]
437 lappend res
[$r get a
]
438 lappend res
[$r get b
]
441 } {hello world foo bared
}
443 test
{Basic LPOP
/RPOP
} {
448 list [$r lpop mylist
] [$r rpop mylist
] [$r lpop mylist
] [$r llen mylist
]
451 test
{LPOP
/RPOP against empty
list} {
455 test
{LPOP against non
list value
} {
457 catch {$r lpop notalist
} err
461 test
{Mass LPUSH
/LPOP
} {
463 for {set i
0} {$i < 1000} {incr i
} {
468 for {set i
0} {$i < 500} {incr i
} {
469 incr sum2
[$r lpop mylist
]
470 incr sum2
[$r rpop mylist
]
475 test
{LRANGE basics
} {
476 for {set i
0} {$i < 10} {incr i
} {
479 list [$r lrange mylist
1 -2] \
480 [$r lrange mylist
-3 -1] \
481 [$r lrange mylist
4 4]
482 } {{1 2 3 4 5 6 7 8} {7 8 9} 4}
484 test
{LRANGE inverted indexes
} {
488 test
{LRANGE out of range indexes including the full
list} {
489 $r lrange mylist
-1000 1000
490 } {0 1 2 3 4 5 6 7 8 9}
492 test
{LRANGE against non existing key
} {
493 $r lrange nosuchkey
0 1
496 test
{LTRIM basics
} {
498 for {set i
0} {$i < 100} {incr i
} {
502 $r lrange mylist
0 -1
507 $r lset mylist
-1 bar
508 $r lrange mylist
0 -1
511 test
{LSET out of range index
} {
512 catch {$r lset mylist
10 foo
} err
516 test
{LSET against non existing key
} {
517 catch {$r lset nosuchkey
10 foo
} err
521 test
{LSET against non
list value
} {
523 catch {$r lset nolist
0 foo
} err
527 test
{SADD
, SCARD
, SISMEMBER
, SMEMBERS basics
} {
530 list [$r scard myset
] [$r sismember myset foo
] \
531 [$r sismember myset bar
] [$r sismember myset bla
] \
532 [lsort [$r smembers myset
]]
533 } {2 1 1 0 {bar foo
}}
535 test
{SADD adding the same element multiple times
} {
542 test
{SADD against non
set} {
543 catch {$r sadd mylist foo
} err
550 lsort [$r smembers myset
]
553 test
{Mass SADD and SINTER with two sets
} {
554 for {set i
0} {$i < 1000} {incr i
} {
556 $r sadd set2
[expr $i+995]
558 lsort [$r sinter set1 set2
]
559 } {995 996 997 998 999}
561 test
{SUNION with two sets
} {
562 lsort [$r sunion set1 set2
]
563 } [lsort -uniq "[$r smembers set1] [$r smembers set2]"]
565 test
{SINTERSTORE with two sets
} {
566 $r sinterstore setres set1 set2
567 lsort [$r smembers setres
]
568 } {995 996 997 998 999}
570 test
{SINTERSTORE with two sets
, after a DEBUG RELOAD
} {
572 $r sinterstore setres set1 set2
573 lsort [$r smembers setres
]
574 } {995 996 997 998 999}
576 test
{SUNIONSTORE with two sets
} {
577 $r sunionstore setres set1 set2
578 lsort [$r smembers setres
]
579 } [lsort -uniq "[$r smembers set1] [$r smembers set2]"]
581 test
{SINTER against three sets
} {
586 lsort [$r sinter set1 set2 set3
]
589 test
{SINTERSTORE with three sets
} {
590 $r sinterstore setres set1 set2 set3
591 lsort [$r smembers setres
]
594 test
{SUNION with non existing keys
} {
595 lsort [$r sunion nokey1 set1 set2 nokey2
]
596 } [lsort -uniq "[$r smembers set1] [$r smembers set2]"]
598 test
{SDIFF with two sets
} {
599 for {set i
5} {$i < 1000} {incr i
} {
602 lsort [$r sdiff set1 set4
]
605 test
{SDIFF with three sets
} {
607 lsort [$r sdiff set1 set4 set5
]
610 test
{SDIFFSTORE with three sets
} {
611 $r sdiffstore sres set1 set4 set5
612 lsort [$r smembers sres
]
620 list [lsort [list [$r spop myset
] [$r spop myset
] [$r spop myset
]]] [$r scard myset
]
623 test
{SAVE
- make sure there are all the types as values
} {
624 # Wait for a background saving in progress to terminate
627 if {[string match
{*bgsave_in_progress
:1*} $i]} {
628 puts -nonewline "\nWaiting for background save to finish... "
635 $r lpush mysavelist hello
636 $r lpush mysavelist world
638 $r set mynormalkey
{blablablba
}
639 $r zadd mytestzset a
10
640 $r zadd mytestzset b
20
641 $r zadd mytestzset c
30
650 unset -nocomplain myset
652 for {set i
0} {$i < 100} {incr i
} {
653 set myset
([$r srandmember myset
]) 1
655 lsort [array names myset
]
658 test
{Create a random
list} {
660 array set seenrand
{}
661 for {set i
0} {$i < 10000} {incr i
} {
663 # Make sure all the weights are different because
664 # Redis does not use a stable sort but Tcl does.
665 set rint
[expr int
(rand
()*1000000)]
666 if {![info exists seenrand
($rint)]} break
668 set seenrand
($rint) x
670 $r set weight_
$i $rint
671 lappend tosort
[list $i $rint]
673 set sorted
[lsort -index 1 -real $tosort]
675 for {set i
0} {$i < 10000} {incr i
} {
676 lappend res
[lindex $sorted $i 0]
681 test
{SORT with BY against the newly created
list} {
682 $r sort tosort
{BY weight_
*}
685 test
{SORT direct
, numeric
, against the newly created
list} {
687 } [lsort -integer $res]
689 test
{SORT decreasing sort
} {
690 $r sort tosort
{DESC
}
691 } [lsort -decreasing -integer $res]
693 test
{SORT speed
, sorting
10000 elements
list using BY
, 100 times
} {
694 set start
[clock clicks
-milliseconds]
695 for {set i
0} {$i < 100} {incr i
} {
696 set sorted
[$r sort tosort
{BY weight_
* LIMIT
0 10}]
698 set elapsed
[expr [clock clicks
-milliseconds]-$start]
699 puts -nonewline "\n Average time to sort: [expr double($elapsed)/100] milliseconds "
704 test
{SORT speed
, sorting
10000 elements
list directly
, 100 times
} {
705 set start
[clock clicks
-milliseconds]
706 for {set i
0} {$i < 100} {incr i
} {
707 set sorted
[$r sort tosort
{LIMIT
0 10}]
709 set elapsed
[expr [clock clicks
-milliseconds]-$start]
710 puts -nonewline "\n Average time to sort: [expr double($elapsed)/100] milliseconds "
715 test
{SORT speed
, pseudo-sorting
10000 elements
list, BY
<const
>, 100 times
} {
716 set start
[clock clicks
-milliseconds]
717 for {set i
0} {$i < 100} {incr i
} {
718 set sorted
[$r sort tosort
{BY nokey LIMIT
0 10}]
720 set elapsed
[expr [clock clicks
-milliseconds]-$start]
721 puts -nonewline "\n Average time to sort: [expr double($elapsed)/100] milliseconds "
726 test
{SORT regression
for issue
#19, sorting floats} {
728 foreach x
{1.1 5.10 3.10 7.44 2.1 5.75 6.12 0.25 1.15} {
732 } [lsort -real {1.1 5.10 3.10 7.44 2.1 5.75 6.12 0.25 1.15}]
734 test
{SORT with GET
#} {
739 $r mset weight_1
10 weight_2
5 weight_3
30
740 $r sort mylist BY weight_
* GET
#
743 test
{LREM
, remove all the occurrences
} {
747 $r rpush mylist foobar
748 $r rpush mylist foobared
753 set res
[$r lrem mylist
0 bar
]
754 list [$r lrange mylist
0 -1] $res
755 } {{foo foobar foobared zap test foo
} 2}
757 test
{LREM
, remove the first occurrence
} {
758 set res
[$r lrem mylist
1 foo
]
759 list [$r lrange mylist
0 -1] $res
760 } {{foobar foobared zap test foo
} 1}
762 test
{LREM
, remove non existing element
} {
763 set res
[$r lrem mylist
1 nosuchelement
]
764 list [$r lrange mylist
0 -1] $res
765 } {{foobar foobared zap test foo
} 0}
767 test
{LREM
, starting from tail with negative count
} {
771 $r rpush mylist foobar
772 $r rpush mylist foobared
778 set res
[$r lrem mylist
-1 bar
]
779 list [$r lrange mylist
0 -1] $res
780 } {{foo bar foobar foobared zap test foo foo
} 1}
782 test
{LREM
, starting from tail with negative count
(2)} {
783 set res
[$r lrem mylist
-2 foo
]
784 list [$r lrange mylist
0 -1] $res
785 } {{foo bar foobar foobared zap test
} 2}
787 test
{LREM
, deleting objects that may be encoded as integers
} {
788 $r lpush myotherlist
1
789 $r lpush myotherlist
2
790 $r lpush myotherlist
3
791 $r lrem myotherlist
1 2
802 test
{MGET against non existing key
} {
803 $r mget foo baazz bar
806 test
{MGET against non-string key
} {
809 $r mget foo baazz bar myset
818 for {set i
0} {$i < 100} {incr i
} {
819 set rkey
[$r randomkey
]
820 if {$rkey eq
{foo
}} {
823 if {$rkey eq
{bar
}} {
827 list $foo_seen $bar_seen
830 test
{RANDOMKEY against empty DB
} {
835 test
{RANDOMKEY regression
1} {
842 test
{GETSET
(set new value
)} {
843 list [$r getset foo xyz
] [$r get foo
]
846 test
{GETSET
(replace old value
)} {
848 list [$r getset foo xyz
] [$r get foo
]
851 test
{SMOVE basics
} {
858 $r smove myset1 myset2 a
859 list [lsort [$r smembers myset2
]] [lsort [$r smembers myset1
]]
862 test
{SMOVE non existing key
} {
863 list [$r smove myset1 myset2 foo
] [lsort [$r smembers myset2
]] [lsort [$r smembers myset1
]]
864 } {0 {a x y z
} {b c
}}
866 test
{SMOVE non existing src
set} {
867 list [$r smove noset myset2 foo
] [lsort [$r smembers myset2
]]
870 test
{SMOVE non existing dst
set} {
871 list [$r smove myset2 myset3 y
] [lsort [$r smembers myset2
]] [lsort [$r smembers myset3
]]
874 test
{SMOVE wrong src key type
} {
876 catch {$r smove x myset2 foo
} err
880 test
{SMOVE wrong dst key type
} {
882 catch {$r smove myset2 x foo
} err
886 test
{MSET base case
} {
887 $r mset x
10 y
"foo bar" z
"x x x x x x x\n\n\r\n"
889 } [list 10 {foo bar
} "x x x x x x x\n\n\r\n"]
891 test
{MSET wrong number of args
} {
892 catch {$r mset x
10 y
"foo bar" z
} err
896 test
{MSETNX with already existent key
} {
897 list [$r msetnx x1 xxx y2 yyy x
20] [$r exists x1
] [$r exists y2
]
900 test
{MSETNX with not existing keys
} {
901 list [$r msetnx x1 xxx y2 yyy
] [$r get x1
] [$r get y2
]
904 test
{ZSET basic ZADD and score
update} {
908 set aux1
[$r zrange ztmp
0 -1]
910 set aux2
[$r zrange ztmp
0 -1]
917 for {set i
0} {$i < 1000} {incr i
} {
918 set score
[expr rand
()]
920 $r zadd zscoretest
$score $i
922 for {set i
0} {$i < 1000} {incr i
} {
923 if {[$r zscore zscoretest
$i] != [lindex $aux $i]} {
924 set err
"Expected score was [lindex $aux $i] but got [$r zscore zscoretest $i] for element $i"
931 test
{ZSCORE
after a DEBUG RELOAD
} {
935 for {set i
0} {$i < 1000} {incr i
} {
936 set score
[expr rand
()]
938 $r zadd zscoretest
$score $i
941 for {set i
0} {$i < 1000} {incr i
} {
942 if {[$r zscore zscoretest
$i] != [lindex $aux $i]} {
943 set err
"Expected score was [lindex $aux $i] but got [$r zscore zscoretest $i] for element $i"
950 test
{ZRANGE and ZREVRANGE
} {
951 list [$r zrange ztmp
0 -1] [$r zrevrange ztmp
0 -1]
954 test
{ZSETs stress tester
- sorting is working well?
} {
956 for {set test
0} {$test < 2} {incr test
} {
957 unset -nocomplain auxarray
958 array set auxarray
{}
961 for {set i
0} {$i < 1000} {incr i
} {
963 set score
[expr rand
()]
965 set score
[expr int
(rand
()*10)]
967 set auxarray
($i) $score
968 $r zadd myzset
$score $i
970 if {[expr rand
()] < .2} {
971 set j
[expr int
(rand
()*1000)]
973 set score
[expr rand
()]
975 set score
[expr int
(rand
()*10)]
977 set auxarray
($j) $score
978 $r zadd myzset
$score $j
981 foreach {item score
} [array get auxarray
] {
982 lappend auxlist
[list $score $item]
984 set sorted
[lsort -command zlistAlikeSort
$auxlist]
987 lappend auxlist
[lindex $x 1]
989 set fromredis
[$r zrange myzset
0 -1]
991 for {set i
0} {$i < [llength $fromredis]} {incr i
} {
992 if {[lindex $fromredis $i] != [lindex $auxlist $i]} {
1000 test
{ZINCRBY
- can create a new sorted
set} {
1002 $r zincrby zset
1 foo
1003 list [$r zrange zset
0 -1] [$r zscore zset foo
]
1006 test
{ZINCRBY
- increment and decrement
} {
1007 $r zincrby zset
2 foo
1008 $r zincrby zset
1 bar
1009 set v1
[$r zrange zset
0 -1]
1010 $r zincrby zset
10 bar
1011 $r zincrby zset
-5 foo
1012 $r zincrby zset
-5 bar
1013 set v2
[$r zrange zset
0 -1]
1014 list $v1 $v2 [$r zscore zset foo
] [$r zscore zset bar
]
1015 } {{bar foo
} {foo bar
} -2 6}
1017 test
{ZRANGEBYSCORE basics
} {
1024 $r zrangebyscore zset
2 4
1027 test
{ZRANGEBYSCORE fuzzy test
, 100 ranges in
1000 elements sorted
set} {
1030 for {set i
0} {$i < 1000} {incr i
} {
1031 $r zadd zset
[expr rand
()] $i
1033 for {set i
0} {$i < 100} {incr i
} {
1034 set min
[expr rand
()]
1035 set max
[expr rand
()]
1041 set low
[$r zrangebyscore zset
-inf $min]
1042 set ok
[$r zrangebyscore zset
$min $max]
1043 set high
[$r zrangebyscore zset
$max +inf
]
1045 set score
[$r zscore zset
$x]
1046 if {$score > $min} {
1047 append err
"Error, score for $x is $score > $min\n"
1051 set score
[$r zscore zset
$x]
1052 if {$score < $min ||
$score > $max} {
1053 append err
"Error, score for $x is $score outside $min-$max range\n"
1057 set score
[$r zscore zset
$x]
1058 if {$score < $max} {
1059 append err
"Error, score for $x is $score < $max\n"
1066 test
{ZRANGEBYSCORE with LIMIT
} {
1074 [$r zrangebyscore zset
0 10 LIMIT
0 2] \
1075 [$r zrangebyscore zset
0 10 LIMIT
2 3] \
1076 [$r zrangebyscore zset
0 10 LIMIT
2 10] \
1077 [$r zrangebyscore zset
0 10 LIMIT
20 10]
1078 } {{a b
} {c d e
} {c d e
} {}}
1080 test
{ZREMRANGE basics
} {
1087 list [$r zremrangebyscore zset
2 4] [$r zrange zset
0 -1]
1090 test
{ZREMRANGE from
-inf to
+inf
} {
1097 list [$r zremrangebyscore zset
-inf +inf
] [$r zrange zset
0 -1]
1100 test
{SORT against sorted sets
} {
1107 $r sort zset alpha desc
1110 test
{Sorted sets
+inf and
-inf handling
} {
1115 $r zadd zset
1000000 d
1116 $r zadd zset
+inf max
1117 $r zadd zset
-inf min
1121 test
{EXPIRE
- don't
set timeouts multiple times
} {
1123 set v1
[$r expire x
5]
1125 set v3
[$r expire x
10]
1127 list $v1 $v2 $v3 $v4
1130 test
{EXPIRE
- It should be still possible to
read 'x'
} {
1134 test
{EXPIRE
- After
6 seconds the key should no longer be here
} {
1136 list [$r get x
] [$r exists x
]
1139 test
{EXPIRE
- Delete on write policy
} {
1147 test
{EXPIREAT
- Check
for EXPIRE alike behavior
} {
1150 $r expireat x
[expr [clock seconds
]+15]
1154 test
{ZSETs skiplist implementation backlink consistency test
} {
1157 for {set j
0} {$j < $elements} {incr j
} {
1158 $r zadd myzset
[expr rand
()] "Element-$j"
1159 $r zrem myzset
"Element-[expr int(rand()*$elements)]"
1161 set l1
[$r zrange myzset
0 -1]
1162 set l2
[$r zrevrange myzset
0 -1]
1163 for {set j
0} {$j < [llength $l1]} {incr j
} {
1164 if {[lindex $l1 $j] ne
[lindex $l2 end-
$j]} {
1171 foreach fuzztype
{binary alpha compr
} {
1172 test
"FUZZ stresser with data model $fuzztype" {
1174 for {set i
0} {$i < 10000} {incr i
} {
1175 set fuzz
[randstring
0 512 $fuzztype]
1177 set got
[$r get foo
]
1178 if {$got ne
$fuzz} {
1179 set err
[list $fuzz $got]
1187 # Leave the user with a clean DB before to exit
1192 lappend aux
[$r dbsize
]
1195 lappend aux
[$r dbsize
]
1198 test
{Perform a final SAVE to leave a clean DB on disk
} {
1203 if {[string match
{*Darwin
*} [exec uname
-a]]} {
1204 test
{Check
for memory leaks
} {
1205 exec leaks redis-server
1210 puts "\n[expr $::passed+$::failed] tests, $::passed passed, $::failed failed"
1211 if {$::failed > 0} {
1212 puts "\n*** WARNING!!! $::failed FAILED TESTS ***\n"
1222 set randkey
[expr int
(rand
()*10000)]
1223 set randval
[expr int
(rand
()*10000)]
1224 set randidx0
[expr int
(rand
()*10)]
1225 set randidx1
[expr int
(rand
()*10)]
1226 set cmd
[expr int
(rand
()*20)]
1228 if {$cmd == 0} {$r set $randkey $randval}
1229 if {$cmd == 1} {$r get
$randkey}
1230 if {$cmd == 2} {$r incr $randkey}
1231 if {$cmd == 3} {$r lpush
$randkey $randval}
1232 if {$cmd == 4} {$r rpop
$randkey}
1233 if {$cmd == 5} {$r del
$randkey}
1234 if {$cmd == 6} {$r llen
$randkey}
1235 if {$cmd == 7} {$r lrange $randkey $randidx0 $randidx1}
1236 if {$cmd == 8} {$r ltrim
$randkey $randidx0 $randidx1}
1237 if {$cmd == 9} {$r lindex $randkey $randidx0}
1238 if {$cmd == 10} {$r lset $randkey $randidx0 $randval}
1239 if {$cmd == 11} {$r sadd
$randkey $randval}
1240 if {$cmd == 12} {$r srem
$randkey $randval}
1241 if {$cmd == 13} {$r smove
$randkey $randval}
1242 if {$cmd == 14} {$r scard
$randkey}
1243 if {$cmd == 15} {$r expire
$randkey [expr $randval%60]}
1251 # Before to run the test check if DB 9 and DB 10 are empty
1254 set db9size
[$r dbsize
]
1256 set db10size
[$r dbsize
]
1257 if {$db9size != 0 ||
$db10size != 0} {
1258 puts "Can't run the tests against DB 9 and 10: DBs are not empty."
1266 if {[llength $argv] == 0} {
1268 } elseif
{[llength $argv] == 1 && [lindex $argv 0] eq
{stress
}} {
1271 main
[lindex $argv 0] [lindex $argv 1]