maxmemory-policy, based on your business type. The default policy is noeviction (which does not evict any keys). When memory is fully utilized, this policy rejects all write operations and returns an OOM error. We recommend that you modify the eviction policy immediately after an instance is created to prevent service interruption due to memory exhaustion. For instructions on how to configure parameters, see Managing Instance Parameters.Abbreviation | Full Name | Description |
LRU | Least Recently Used | Least recently used. Tracks the last access time of each key, and prioritizes evicting the keys that have been least recently accessed. |
LFU | Least Frequently Used | Least frequently used. Tracks the number of accesses of each key, and prioritizes evicting the keys with the fewest accesses. |
TTL | Time To Live | Time to live. Measures the remaining time for a key before it expires. |
Policy | Scope | Eviction Rule |
allkeys-lru | All keys | Prioritizes evicting the least recently used keys until sufficient space is freed. |
allkeys-lfu | All keys | Prioritizes evicting the least frequently accessed keys until sufficient space is freed. |
allkeys-random | All keys | Randomly evicts keys until sufficient space is freed. |
volatile-lru | Keys with an expiration time set | Prioritizes evicting the least recently used keys among those with a TTL set. |
volatile-lfu | Keys with an expiration time set | Prioritizes evicting the least frequently accessed keys among those with a TTL set. |
volatile-ttl | Keys with an expiration time set | Prioritizes evicting keys with a smaller TTL value (that is, those about to expire). If no keys have a TTL set, rolls back to the noeviction policy. |
volatile-random | Keys with an expiration time set | Randomly evicts keys with an expiration time set. |
noeviction | — | Does not delete any data, rejects all write operations and returns the error message "(error) OOM command not allowed when used memory", and only responds to read operations at this time. |
volatile-lru serves only as a fallback option for hybrid scenarios.Scenario | Recommended Policy | Description |
Use as a Pure Cache (Recommended). | allkeys-lru | All keys can be evicted, with the least recently accessed keys removed first. Keys with the lowest access frequency have the lowest subsequent hit probability, resulting in minimal business impact after eviction. |
Some Keys Need to Be Persistently Retained. | volatile-lru | Evicts only keys with an expiration time set, leaving keys without an expiration time unaffected. Suitable for hybrid scenarios containing both cache data (with TTL set) and configuration data (without TTL set). |
Requires Precise Control Over Key Lifecycle. | volatile-ttl | Prioritizes evicting keys that are about to expire, suitable for scenarios with explicit requirements on data timeliness. |
noeviction to allkeys-lru.# View the current eviction policy.CONFIG GET maxmemory-policy# Set it to allkeys-lru.CONFIG SET maxmemory-policy allkeys-lru
Configuration Method | Issue Description |
Using the default noeviction policy without modification. | All write operations are rejected after memory is full, an OOM error is returned, and service writes are interrupted. |
Using volatile-lru when no keys have TTL set. | The volatile-* policy only applies to keys with an expiration time set. If no keys have a TTL set, it is equivalent to the noeviction policy, and memory cannot be freed. |
Using the allkeys-random policy to handle prioritized cache data. | Random eviction does not distinguish access frequency, which may accidentally delete frequently accessed hot keys, leading to a decrease in cache hit rate. |
フィードバック