>_ IzzyLab

Hands-on task

This task is step 5 of the course “Redis in production”

A cache that never refuses writes

medium~7 min

This Redis is a cache: losing old keys is no big deal, but an OOM command not allowed error is an outage for the application.

Configure it:

  • memory limit 20 MB (20mb);
  • eviction policy allkeys-lru — when full, delete the least recently used keys.

The settings must take effect now, without a restart, and be persisted in /etc/redis/redis.conf.

Open the config /etc/redis/redis.conf in the Editor tab.

What you'll practise:
  • redis
  • maxmemory
  • maxmemory-policy
  • allkeys-lru
  • eviction
  • CONFIG REWRITE

Topic breakdown

When Redis hits maxmemory, it acts according to maxmemory-policy. The default is noeviction: reads work, and every write gets an OOM error — right for a data store where data must not be lost, and fatal for a cache. The allkeys-lru/allkeys-lfu policies evict least recently or least frequently used keys from the whole dataset, volatile-* — only keys with a TTL, allkeys-random — random ones. LRU in Redis is approximate: it samples maxmemory-samples keys and throws out the best candidate. Without an explicit maxmemory a cache grows up to the container or OS limit and gets killed by the OOM killer — so you always set a limit and persist it in the config, otherwise a restart silently brings back the old behavior.

What's checked

  1. 20 MB limit in effect
  2. allkeys-lru policy in effect
  3. settings saved in redis.conf
  4. writes beyond the limit succeed without OOM

What it looks like