Implements TTL and PTTL */
| 555 | |
| 556 | /* Implements TTL and PTTL */ |
| 557 | void ttlGenericCommand(client *c, int output_ms) { |
| 558 | long long expire, ttl = -1; |
| 559 | |
| 560 | /* If the key does not exist at all, return -2 */ |
| 561 | if (lookupKeyReadWithFlags(c->db,c->argv[1],LOOKUP_NOTOUCH) == NULL) { |
| 562 | addReplyLongLong(c,-2); |
| 563 | return; |
| 564 | } |
| 565 | /* The key exists. Return -1 if it has no expire, or the actual |
| 566 | * TTL value otherwise. */ |
| 567 | expire = getExpire(c->db,c->argv[1]); |
| 568 | if (expire != -1) { |
| 569 | ttl = expire-mstime(); |
| 570 | if (ttl < 0) ttl = 0; |
| 571 | } |
| 572 | if (ttl == -1) { |
| 573 | addReplyLongLong(c,-1); |
| 574 | } else { |
| 575 | addReplyLongLong(c,output_ms ? ttl : ((ttl+500)/1000)); |
| 576 | } |
| 577 | } |
| 578 | |
| 579 | /* TTL key */ |
| 580 | void ttlCommand(client *c) { |
no test coverage detected