A Redis instance with no maxmemory set will use all the RAM it can take and then crash. A Redis with maxmemory set but the wrong maxmemory-policy will evict the wrong keys and become useless as a cache. On a multi-tenant cPanel host where Redis serves WordPress object caches for many accounts, the eviction policy is the single most important Redis setting. Most teams leave it at the default and never look again.
What’s happening
Redis offers eight eviction policies:
noeviction— never evict; new writes fail with an error when full. Right for queue/persistent use, wrong for cache.allkeys-lru— evict the least recently used key, regardless of TTL. Right for general cache.allkeys-lfu— least frequently used. Better than LRU for caches where some keys are hot and others rarely accessed.volatile-lru,volatile-lfu— same as above, but only evict keys with a TTL set. If all keys have TTL, equivalent to allkeys.volatile-ttl— evict the key with the shortest remaining TTL first.allkeys-random,volatile-random— random eviction. Cheap to compute, terrible cache behavior.
For a WordPress object cache, most keys have no TTL (object cache stores until invalidated by code). volatile-lru would refuse to evict and behave like noeviction. allkeys-lru evicts cleanly. allkeys-lfu is usually best on a busy site because hot keys (homepage data, popular posts) stay cached while one-shot lookups get evicted.
How to verify
Current policy and memory state:
redis-cli CONFIG GET maxmemory
redis-cli CONFIG GET maxmemory-policy
redis-cli INFO memory | grep -E 'used_memory_human|maxmemory_human|evicted_keys'
redis-cli INFO stats | grep -E 'keyspace_hits|keyspace_misses|evicted_keys'
Hit rate = keyspace_hits / (keyspace_hits + keyspace_misses). Anything below 85% means the cache is not retaining the working set. Combine with evicted_keys growth rate — fast eviction + low hit rate = wrong policy or too-small maxmemory.
The fix
-
Set maxmemory to a realistic fraction of host RAM. On a 32 GB host running MySQL, PHP-FPM, Apache, and Redis as a cache, Redis can have 4-8 GB. Bigger is not always better — diminishing returns past the working set size.
-
Set policy to
allkeys-lfufor WordPress object cache use:redis-cli CONFIG SET maxmemory 4gb redis-cli CONFIG SET maxmemory-policy allkeys-lfuThen persist in
/etc/redis.conf:maxmemory 4gb maxmemory-policy allkeys-lfu -
Monitor over a week.
keyspace_hitsrate should be above 90%;evicted_keysshould grow steadily but slowly (not in bursts). -
For per-tenant Redis instances (one Redis per cPanel user via Unix socket), set tighter maxmemory per instance — usually 128 MB to 512 MB depending on the site. One per-tenant instance hitting eviction does not affect other tenants.
-
Avoid
FLUSHDBandFLUSHALLon a shared instance unless you mean to wipe everyone’s cache. Use per-key DEL or per-prefix SCAN+DEL for selective invalidation.
After tuning, the cache hit rate is the metric to watch. Stack Harbor configures Redis for shared cPanel hosts as part of managed cPanel operations.