1. Be sure to set the maximum cache size and set the cache policy
If you do not set the maximum cache, the Redis crashes when the new data is added, if the maximum memory is exceeded!
Setting mode: MaxMemory 1GB
After logging in using REDIS-CLI, use the Info command to view the memory situation:
# Memory
used_memory:882920
How much memory is consumed by used_memory_human:862.23k data
used_memory_rss:2412544
used_memory_rss_human:2.30m
used_memory_peak:898688
used_memory_peak_human:877.62k
total_system_memory:4044341248
total_system_memory_human:3.77g
used_memory_lua:37888
used_memory_lua_human:37.00k
maxmemory:0
maxmemory_human:1.00g the peak of memory consumption
Maxmemory_policy:noeviction
mem_fragmentation_ratio:2.73
mem_allocator:libc
2. Cache Policy
When the maxmemory limit arrives, the exact behavior that Redis will take is configured by the Maxmemory-policy configuration directive.
- Noeviction-Returns an error when memory limit is reached
- ALLKEYS-LRU-Recycles The least recently used (LRU) key to make room for new data.
- VOLATILE-LRU-Recycles The least recently used (LRU) key, but reclaims only the keys that have expired settings, freeing up space for new data.
- Allkeys-random-Reclaim random keys to make room for new data.
- Volatile-random-reclaims random keys, but reclaims only the keys that are set to expire, freeing up space for new data.
- Volatile-ttl-Recycle a key with set expiration, try to reclaim the key from the minimum TTL time to make room for new data.
Redis Cache Settings