2 · REDIS · MEMORY
Memory: The limit and policy are specified explicitly
lab: experience only with Redis-memory (8 MB)
Example of a clean cache
CONFIG GET maxmemory maxmemory-policy
-> 8388608, noeviction
SET lesson03:fill:N <128 KiB> …
-> OOM command not allowed …
GET lesson03:fill:0 -> read works
CONFIG SET maxmemory-policy allkeys-lru
-> 80 entries, evicted_keys is increasing
maxmemory 2gb
maxmemory-policy allkeys-lru
// maxmemory 0 — no Redis limit:
// grows up to the container/OS limit,
// process may be killed due to OOM
noeviction
allkeys-lru
volatile-ttl
When the limit is reached, memory expansion commands are rejected. GET and DEL commands work. Main Redis lab: 32 MB.
An approximate LRU across all keys, regardless of TTL. For a recoverable cache.
Only keys with a TTL that is about to expire. Sessions with a TTL are also candidates.
SELECT does not isolate memory or the policy. The cache and critical state are different Redis instances. “Redis will clean everything up on its own” is incorrect: the limit and policy must be explicitly specified.
▶ P17: Safety
▶ P14: Large Keys