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

Function objectSetLRUOrLFU

src/object.cpp:1294–1320  ·  view source on GitHub ↗

Set the object LRU/LFU depending on g_pserver->maxmemory_policy. * The lfu_freq arg is only relevant if policy is MAXMEMORY_FLAG_LFU. * The lru_idle and lru_clock args are only relevant if policy * is MAXMEMORY_FLAG_LRU. * Either or both of them may be <0, in that case, nothing is set. */

Source from the content-addressed store, hash-verified

1292 * is MAXMEMORY_FLAG_LRU.
1293 * Either or both of them may be <0, in that case, nothing is set. */
1294int objectSetLRUOrLFU(robj *val, long long lfu_freq, long long lru_idle,
1295 long long lru_clock, int lru_multiplier) {
1296 if (g_pserver->maxmemory_policy & MAXMEMORY_FLAG_LFU) {
1297 if (lfu_freq >= 0) {
1298 serverAssert(lfu_freq <= 255);
1299 val->lru = (LFUGetTimeInMinutes()<<8) | lfu_freq;
1300 return 1;
1301 }
1302 } else if (lru_idle >= 0) {
1303 /* Provided LRU idle time is in seconds. Scale
1304 * according to the LRU clock resolution this Redis
1305 * instance was compiled with (normally 1000 ms, so the
1306 * below statement will expand to lru_idle*1000/1000. */
1307 lru_idle = lru_idle*lru_multiplier/LRU_CLOCK_RESOLUTION;
1308 long lru_abs = lru_clock - lru_idle; /* Absolute access time. */
1309 /* If the LRU field underflows (since LRU it is a wrapping
1310 * clock), the best we can do is to provide a large enough LRU
1311 * that is half-way in the circlular LRU clock we use: this way
1312 * the computed idle time for this object will stay high for quite
1313 * some time. */
1314 if (lru_abs < 0)
1315 lru_abs = (lru_clock+(LRU_CLOCK_MAX/2)) % LRU_CLOCK_MAX;
1316 val->lru = lru_abs;
1317 return 1;
1318 }
1319 return 0;
1320}
1321
1322/* ======================= The OBJECT and MEMORY commands =================== */
1323

Callers 4

restoreCommandFunction · 0.85
processJobMethod · 0.85
RM_SetLRUFunction · 0.85
RM_SetLFUFunction · 0.85

Calls 1

LFUGetTimeInMinutesFunction · 0.85

Tested by

no test coverage detected