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. */
| 1862 | * to NULL. The 'when' parameter is the absolute unix time in milliseconds |
| 1863 | * after which the key will no longer be considered valid. */ |
| 1864 | void 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 | |
| 1889 | redisDb::~redisDb() |
| 1890 | { |
no test coverage detected