mirror of
https://github.com/fluencelabs/redis
synced 2025-06-13 01:01:22 +00:00
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.
This commit is contained in:
7
src/db.c
7
src/db.c
@ -603,6 +603,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;
|
||||
|
Reference in New Issue
Block a user