X-Git-Url: https://git.saurik.com/redis.git/blobdiff_plain/64c7499eb88040c26aba264ab52756fd764d8fa4..bfc197c3b604baf0dba739ea174d5054284133f0:/tests/unit/expire.tcl diff --git a/tests/unit/expire.tcl b/tests/unit/expire.tcl index 6130e842..56a59f76 100644 --- a/tests/unit/expire.tcl +++ b/tests/unit/expire.tcl @@ -79,9 +79,9 @@ start_server {tags {"expire"}} { for {set j 0} {$j < 3} {incr j} { r del x r setex x 1 somevalue - after 997 + after 900 set a [r get x] - after 1002 + after 1100 set b [r get x] if {$a eq {somevalue} && $b eq {}} break } @@ -95,23 +95,23 @@ start_server {tags {"expire"}} { for {set j 0} {$j < 3} {incr j} { r del x y z r psetex x 100 somevalue - after 97 + after 80 set a [r get x] - after 102 + after 120 set b [r get x] r set x somevalue r pexpire x 100 - after 97 + after 80 set c [r get x] - after 102 + after 120 set d [r get x] r set x somevalue r pexpireat x [expr ([clock seconds]*1000)+100] - after 97 + after 80 set e [r get x] - after 102 + after 120 set f [r get x] if {$a eq {somevalue} && $b eq {} && @@ -127,4 +127,29 @@ start_server {tags {"expire"}} { set ttl [r pttl x] assert {$ttl > 900 && $ttl <= 1000} } + + test {Redis should actively expire keys incrementally} { + r flushdb + r psetex key1 500 a + r psetex key2 500 a + r psetex key3 500 a + set size1 [r dbsize] + # Redis expires random keys ten times every second so we are + # fairly sure that all the three keys should be evicted after + # one second. + after 1000 + set size2 [r dbsize] + list $size1 $size2 + } {3 0} + + test {5 keys in, 5 keys out} { + r flushdb + r set a c + r expire a 5 + r set t c + r set e c + r set s c + r set foo b + lsort [r keys *] + } {a e foo s t} }