diff options
author | antirez <antirez@gmail.com> | 2012-11-12 23:04:36 +0100 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2012-11-12 23:04:36 +0100 |
commit | aa2bf6ba8bec776c02d8055ac856d96926137895 (patch) | |
tree | 2a1156440b481cff6d880237ab1bef5ccc4fbb41 /tests | |
parent | 5513397de7526f0e5e01c1d29a37813008703d6d (diff) | |
download | redis-aa2bf6ba8bec776c02d8055ac856d96926137895.tar.gz |
TTL API change: TTL returns -2 for non existing keys.
The previous behavior was to return -1 if:
1) Existing key but without an expire set.
2) Non existing key.
Now the second case is handled in a different, and TTL will return -2
if the key does not exist at all.
PTTL follows the same behavior as well.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/expire.tcl | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/tests/unit/expire.tcl b/tests/unit/expire.tcl index 56a59f768..57497fe5e 100644 --- a/tests/unit/expire.tcl +++ b/tests/unit/expire.tcl @@ -121,13 +121,31 @@ start_server {tags {"expire"}} { list $a $b } {somevalue {}} - test {PTTL returns millisecond time to live} { + test {TTL returns tiem to live in seconds} { + r del x + r setex x 10 somevalue + set ttl [r ttl x] + assert {$ttl > 8 && $ttl <= 10} + } + + test {PTTL returns time to live in milliseconds} { r del x r setex x 1 somevalue set ttl [r pttl x] assert {$ttl > 900 && $ttl <= 1000} } + test {TTL / PTTL return -1 if key has no expire} { + r del x + r set x hello + list [r ttl x] [r pttl x] + } {-1 -1} + + test {TTL / PTTL return -2 if key does not exit} { + r del x + list [r ttl x] [r pttl x] + } {-2 -2} + test {Redis should actively expire keys incrementally} { r flushdb r psetex key1 500 a |