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

Function expireIfNeeded

src/db.cpp:2090–2112  ·  view source on GitHub ↗

This function is called when we are going to perform some operation * in a given key, but such key may be already logically expired even if * it still exists in the database. The main way this function is called * is via lookupKey*() family of functions. * * The behavior of the function depends on the replication role of the * instance, because replica instances do not expire keys, they wait

Source from the content-addressed store, hash-verified

2088 * The return value of the function is 0 if the key is still valid,
2089 * otherwise the function returns 1 if the key is expired. */
2090int expireIfNeeded(redisDb *db, robj *key) {
2091 if (!keyIsExpired(db,key)) return 0;
2092
2093 /* If we are running in the context of a replica, instead of
2094 * evicting the expired key from the database, we return ASAP:
2095 * the replica key expiration is controlled by the master that will
2096 * send us synthesized DEL operations for expired keys.
2097 *
2098 * Still we try to return the right information to the caller,
2099 * that is, 0 if we think the key should be still valid, 1 if
2100 * we think the key is expired at this time. */
2101 if (listLength(g_pserver->masters) && !g_pserver->fActiveReplica) return 1;
2102
2103 /* If clients are paused, we keep the current dataset constant,
2104 * but return to the client what we believe is the right state. Typically,
2105 * at the end of the pause we will properly expire the key OR we will
2106 * have failed over and the new primary will send us the expire. */
2107 if (checkClientPauseTimeoutAndReturnIfPaused()) return 1;
2108
2109 /* Delete the key */
2110 deleteExpiredKeyAndPropagate(db,key);
2111 return 1;
2112}
2113
2114/* -----------------------------------------------------------------------------
2115 * API to get key arguments from commands

Callers 5

lookupKeyReadWithFlagsFunction · 0.85
lookupKeyWriteWithFlagsFunction · 0.85
dbRandomKeyFunction · 0.85
delGenericCommandFunction · 0.85
scanFilterAndReplyFunction · 0.85

Calls 3

keyIsExpiredFunction · 0.85

Tested by

no test coverage detected