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

Function setExpire

src/db.cpp:1864–1887  ·  view source on GitHub ↗

Set an expire to the specified key. If the expire is set in the context * of an user calling a command 'c' is the client, otherwise 'c' is set * to NULL. The 'when' parameter is the absolute unix time in milliseconds * after which the key will no longer be considered valid. */

Source from the content-addressed store, hash-verified

1862 * to NULL. The 'when' parameter is the absolute unix time in milliseconds
1863 * after which the key will no longer be considered valid. */
1864void setExpire(client *c, redisDb *db, robj *key, robj *subkey, long long when) {
1865 serverAssert(GlobalLocksAcquired());
1866
1867 /* Update TTL stats (exponential moving average) */
1868 /* Note: We never have to update this on expiry since we reduce it by the current elapsed time here */
1869 mstime_t now;
1870 __atomic_load(&g_pserver->mstime, &now, __ATOMIC_ACQUIRE);
1871 db->avg_ttl -= (now - db->last_expire_set); // reduce the TTL by the time that has elapsed
1872 if (db->expireSize() == 0)
1873 db->avg_ttl = 0;
1874 else
1875 db->avg_ttl -= db->avg_ttl / db->expireSize(); // slide one entry out the window
1876 if (db->avg_ttl < 0)
1877 db->avg_ttl = 0; // TTLs are never negative
1878 db->avg_ttl += (double)(when-now) / (db->expireSize()+1); // add the new entry
1879 db->last_expire_set = now;
1880
1881 /* Update the expire set */
1882 db->setExpire(key, subkey, when);
1883
1884 int writable_slave = listLength(g_pserver->masters) && g_pserver->repl_slave_ro == 0 && !g_pserver->fActiveReplica;
1885 if (c && writable_slave && !(c->flags & CLIENT_MASTER))
1886 rememberSlaveKeyWithExpire(db,key);
1887}
1888
1889redisDb::~redisDb()
1890{

Callers 12

copyCommandFunction · 0.85
mvccrestoreCommandFunction · 0.85
restoreCommandFunction · 0.85
processJobMethod · 0.85
expireMemberCoreFunction · 0.85
expireGenericCommandFunction · 0.85
RM_SetExpireFunction · 0.85
RM_SetAbsExpireFunction · 0.85
setGenericCommandFunction · 0.85
getexCommandFunction · 0.85
cronCommandFunction · 0.85
executeCronJobExpireHookFunction · 0.85

Calls 12

GlobalLocksAcquiredFunction · 0.85
dupStringObjectFunction · 0.85
removeExpireFunction · 0.85
expireSizeMethod · 0.80
getrefcountMethod · 0.80
updateValueMethod · 0.80
FExpiresMethod · 0.80
setExpireMethod · 0.45
findMethod · 0.45
valMethod · 0.45
keyMethod · 0.45

Tested by

no test coverage detected