X-Git-Url: https://git.saurik.com/redis.git/blobdiff_plain/b9bb7ba22077ed7bf585506d889d0771ba2383da..210e29f7d276be1bbbaf1b711b654dd6834f8e93:/test-redis.tcl diff --git a/test-redis.tcl b/test-redis.tcl index cae0c025..a7acf641 100644 --- a/test-redis.tcl +++ b/test-redis.tcl @@ -235,6 +235,19 @@ proc main {server port} { format $ok } {2000} + test {Check if the list is still ok after a DEBUG RELOAD} { + $r debug reload + set ok 0 + for {set i 0} {$i < 1000} {incr i} { + set rint [expr int(rand()*1000)] + if {[$r lindex mylist $rint] eq $rint} {incr ok} + if {[$r lindex mylist [expr (-$rint)-1]] eq [expr 999-$rint]} { + incr ok + } + } + format $ok + } {2000} + test {LLEN against non-list value error} { $r del mylist $r set mylist foobar @@ -551,6 +564,12 @@ proc main {server port} { lsort [$r smembers setres] } {995 996 997 998 999} + test {SINTERSTORE with two sets, after a DEBUG RELOAD} { + $r debug reload + $r sinterstore setres set1 set2 + lsort [$r smembers setres] + } {995 996 997 998 999} + test {SUNIONSTORE with two sets} { $r sunionstore setres set1 set2 lsort [$r smembers setres] @@ -619,6 +638,19 @@ proc main {server port} { $r zadd mytestzset c 30 $r save } {OK} + + test {SRANDMEMBER} { + $r del myset + $r sadd myset a + $r sadd myset b + $r sadd myset c + unset -nocomplain myset + array set myset {} + for {set i 0} {$i < 100} {incr i} { + set myset([$r srandmember myset]) 1 + } + lsort [array names myset] + } {a b c} test {Create a random list} { set tosort {} @@ -696,6 +728,15 @@ proc main {server port} { $r sort mylist } [lsort -real {1.1 5.10 3.10 7.44 2.1 5.75 6.12 0.25 1.15}] + test {SORT with GET #} { + $r del mylist + $r lpush mylist 1 + $r lpush mylist 2 + $r lpush mylist 3 + $r mset weight_1 10 weight_2 5 weight_3 30 + $r sort mylist BY weight_* GET # + } {2 1 3} + test {LREM, remove all the occurrences} { $r flushdb $r rpush mylist foo @@ -884,6 +925,25 @@ proc main {server port} { set _ $err } {} + test {ZSCORE after a DEBUG RELOAD} { + set aux {} + set err {} + $r del zscoretest + for {set i 0} {$i < 1000} {incr i} { + set score [expr rand()] + lappend aux $score + $r zadd zscoretest $score $i + } + $r debug reload + for {set i 0} {$i < 1000} {incr i} { + if {[$r zscore zscoretest $i] != [lindex $aux $i]} { + set err "Expected score was [lindex $aux $i] but got [$r zscore zscoretest $i] for element $i" + break + } + } + set _ $err + } {} + test {ZRANGE and ZREVRANGE} { list [$r zrange ztmp 0 -1] [$r zrevrange ztmp 0 -1] } {{y x z} {z x y}} @@ -934,6 +994,56 @@ proc main {server port} { format $delta } {0} + test {ZINCRBY - can create a new sorted set} { + $r del zset + $r zincrby zset 1 foo + list [$r zrange zset 0 -1] [$r zscore zset foo] + } {foo 1} + + test {ZINCRBY - increment and decrement} { + $r zincrby zset 2 foo + $r zincrby zset 1 bar + set v1 [$r zrange zset 0 -1] + $r zincrby zset 10 bar + $r zincrby zset -5 foo + $r zincrby zset -5 bar + set v2 [$r zrange zset 0 -1] + list $v1 $v2 [$r zscore zset foo] [$r zscore zset bar] + } {{bar foo} {foo bar} -2 6} + + test {EXPIRE - don't set timeouts multiple times} { + $r set x foobar + set v1 [$r expire x 5] + set v2 [$r ttl x] + set v3 [$r expire x 10] + set v4 [$r ttl x] + list $v1 $v2 $v3 $v4 + } {1 5 0 5} + + test {EXPIRE - It should be still possible to read 'x'} { + $r get x + } {foobar} + + test {EXPIRE - After 6 seconds the key should no longer be here} { + after 6000 + list [$r get x] [$r exists x] + } {{} 0} + + test {EXPIRE - Delete on write policy} { + $r del x + $r lpush x foo + $r expire x 1000 + $r lpush x bar + $r lrange x 0 -1 + } {bar} + + test {EXPIREAT - Check for EXPIRE alike behavior} { + $r del x + $r set x foo + $r expireat x [expr [clock seconds]+15] + $r ttl x + } {1[345]} + test {ZSETs skiplist implementation backlink consistency test} { set diff 0 set elements 10000