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 /src | |
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 'src')
-rw-r--r-- | src/db.c | 7 |
1 files changed, 7 insertions, 0 deletions
@@ -614,6 +614,13 @@ void ttlGenericCommand(redisClient *c, int output_ms) { long long expire, ttl = -1; expire = getExpire(c->db,c->argv[1]); + /* If the key does not exist at all, return -2 */ + if (expire == -1 && lookupKeyRead(c->db,c->argv[1]) == NULL) { + addReplyLongLong(c,-2); + return; + } + /* The key exists. Return -1 if it has no expire, or the actual + * TTL value otherwise. */ if (expire != -1) { ttl = expire-mstime(); if (ttl < 0) ttl = -1; |