MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / ttlGenericCommand

Function ttlGenericCommand

src/expire.cpp:806–850  ·  view source on GitHub ↗

Implements TTL and PTTL */

Source from the content-addressed store, hash-verified

804
805/* Implements TTL and PTTL */
806void ttlGenericCommand(client *c, int output_ms) {
807 long long expire = INVALID_EXPIRE, ttl = -1;
808
809 /* If the key does not exist at all, return -2 */
810 if (lookupKeyReadWithFlags(c->db,c->argv[1],LOOKUP_NOTOUCH) == nullptr) {
811 addReplyLongLong(c,-2);
812 return;
813 }
814
815 /* The key exists. Return -1 if it has no expire, or the actual
816 * TTL value otherwise. */
817 expireEntry *pexpire = c->db->getExpire(c->argv[1]);
818
819 if (c->argc == 2) {
820 // primary expire
821 if (pexpire != nullptr)
822 pexpire->FGetPrimaryExpire(&expire);
823 } else if (c->argc == 3) {
824 // We want a subkey expire
825 if (pexpire && pexpire->FFat()) {
826 for (auto itr : *pexpire) {
827 if (itr.subkey() == nullptr)
828 continue;
829 if (sdscmp((sds)itr.subkey(), szFromObj(c->argv[2])) == 0) {
830 expire = itr.when();
831 break;
832 }
833 }
834 }
835 } else {
836 addReplyError(c, "Invalid arguments");
837 return;
838 }
839
840
841 if (expire != INVALID_EXPIRE) {
842 ttl = expire-mstime();
843 if (ttl < 0) ttl = 0;
844 }
845 if (ttl == -1) {
846 addReplyLongLong(c,-1);
847 } else {
848 addReplyLongLong(c,output_ms ? ttl : ((ttl+500)/1000));
849 }
850}
851
852/* TTL key */
853void ttlCommand(client *c) {

Callers 2

ttlCommandFunction · 0.85
pttlCommandFunction · 0.85

Calls 11

lookupKeyReadWithFlagsFunction · 0.85
addReplyLongLongFunction · 0.85
sdscmpFunction · 0.85
szFromObjFunction · 0.85
addReplyErrorFunction · 0.85
FFatMethod · 0.80
subkeyMethod · 0.80
mstimeFunction · 0.70
getExpireMethod · 0.45
FGetPrimaryExpireMethod · 0.45
whenMethod · 0.45

Tested by

no test coverage detected