]> git.saurik.com Git - redis.git/blob - tests/unit/expire.tcl
fixed another timing issue when running the test over valgrind or with very slow PCs
[redis.git] / tests / unit / expire.tcl
1 start_server {tags {"expire"}} {
2 test {EXPIRE - set timeouts multiple times} {
3 r set x foobar
4 set v1 [r expire x 5]
5 set v2 [r ttl x]
6 set v3 [r expire x 10]
7 set v4 [r ttl x]
8 r expire x 4
9 list $v1 $v2 $v3 $v4
10 } {1 [45] 1 10}
11
12 test {EXPIRE - It should be still possible to read 'x'} {
13 r get x
14 } {foobar}
15
16 tags {"slow"} {
17 test {EXPIRE - After 6 seconds the key should no longer be here} {
18 after 6000
19 list [r get x] [r exists x]
20 } {{} 0}
21 }
22
23 test {EXPIRE - write on expire should work} {
24 r del x
25 r lpush x foo
26 r expire x 1000
27 r lpush x bar
28 r lrange x 0 -1
29 } {bar foo}
30
31 test {EXPIREAT - Check for EXPIRE alike behavior} {
32 r del x
33 r set x foo
34 r expireat x [expr [clock seconds]+15]
35 r ttl x
36 } {1[345]}
37
38 test {SETEX - Set + Expire combo operation. Check for TTL} {
39 r setex x 12 test
40 r ttl x
41 } {1[012]}
42
43 test {SETEX - Check value} {
44 r get x
45 } {test}
46
47 test {SETEX - Overwrite old key} {
48 r setex y 1 foo
49 r get y
50 } {foo}
51
52 tags {"slow"} {
53 test {SETEX - Wait for the key to expire} {
54 after 3000
55 r get y
56 } {}
57 }
58
59 test {SETEX - Wrong time parameter} {
60 catch {r setex z -10 foo} e
61 set _ $e
62 } {*invalid expire*}
63
64 test {PERSIST can undo an EXPIRE} {
65 r set x foo
66 r expire x 50
67 list [r ttl x] [r persist x] [r ttl x] [r get x]
68 } {50 1 -1 foo}
69
70 test {PERSIST returns 0 against non existing or non volatile keys} {
71 r set x foo
72 list [r persist foo] [r persist nokeyatall]
73 } {0 0}
74 }