mirror of
https://github.com/fluencelabs/redis
synced 2025-03-23 02:50:50 +00:00
TTL / PTTL commands: two bugs fixed.
This commit fixes two corner cases for the TTL command. 1) When the key was already logically expired (expire time older than current time) the command returned -1 instead of -2. 2) When the key was existing and the expire was found to be exactly 0 (the key was just about to expire), the command reported -1 (that is, no expire) instead of a TTL of zero (that is, about to expire).
This commit is contained in:
parent
8bb5eb7357
commit
873f328fd8
6
src/db.c
6
src/db.c
@ -626,17 +626,17 @@ void pexpireatCommand(redisClient *c) {
|
||||
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) {
|
||||
if (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. */
|
||||
expire = getExpire(c->db,c->argv[1]);
|
||||
if (expire != -1) {
|
||||
ttl = expire-mstime();
|
||||
if (ttl < 0) ttl = -1;
|
||||
if (ttl < 0) ttl = 0;
|
||||
}
|
||||
if (ttl == -1) {
|
||||
addReplyLongLong(c,-1);
|
||||
|
Loading…
x
Reference in New Issue
Block a user