MCPcopy Create free account
hub / github.com/F-Stack/f-stack / objectSetLRUOrLFU

Function objectSetLRUOrLFU

app/redis-6.2.6/src/object.c:1211–1237  ·  view source on GitHub ↗

Set the object LRU/LFU depending on server.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

1209 * is MAXMEMORY_FLAG_LRU.
1210 * Either or both of them may be <0, in that case, nothing is set. */
1211int objectSetLRUOrLFU(robj *val, long long lfu_freq, long long lru_idle,
1212 long long lru_clock, int lru_multiplier) {
1213 if (server.maxmemory_policy & MAXMEMORY_FLAG_LFU) {
1214 if (lfu_freq >= 0) {
1215 serverAssert(lfu_freq <= 255);
1216 val->lru = (LFUGetTimeInMinutes()<<8) | lfu_freq;
1217 return 1;
1218 }
1219 } else if (lru_idle >= 0) {
1220 /* Provided LRU idle time is in seconds. Scale
1221 * according to the LRU clock resolution this Redis
1222 * instance was compiled with (normally 1000 ms, so the
1223 * below statement will expand to lru_idle*1000/1000. */
1224 lru_idle = lru_idle*lru_multiplier/LRU_CLOCK_RESOLUTION;
1225 long lru_abs = lru_clock - lru_idle; /* Absolute access time. */
1226 /* If the LRU field underflows (since LRU it is a wrapping
1227 * clock), the best we can do is to provide a large enough LRU
1228 * that is half-way in the circlular LRU clock we use: this way
1229 * the computed idle time for this object will stay high for quite
1230 * some time. */
1231 if (lru_abs < 0)
1232 lru_abs = (lru_clock+(LRU_CLOCK_MAX/2)) % LRU_CLOCK_MAX;
1233 val->lru = lru_abs;
1234 return 1;
1235 }
1236 return 0;
1237}
1238
1239/* ======================= The OBJECT and MEMORY commands =================== */
1240

Callers 4

rdbLoadRioFunction · 0.85
restoreCommandFunction · 0.85
RM_SetLRUFunction · 0.85
RM_SetLFUFunction · 0.85

Calls 1

LFUGetTimeInMinutesFunction · 0.85

Tested by

no test coverage detected