Advertisement
Intermediate Redis, Redis Memory Optimization

How do you configure and monitor the maxmemory setting in Redis to prevent it from consuming more memory than your server can safely provide?

Short answer

You set the maxmemory configuration option to a value comfortably below your server's total available RAM, leaving headroom for the operating system and other processes, pair it with an appropriate eviction policy for your use case, and continuously monitor actual memory usage…

Save Redis mock interview
Advertisement
AModel answer
You set the maxmemory configuration option to a value comfortably below your server's total available RAM, leaving headroom for the operating system and other processes, pair it with an appropriate eviction policy for your use case, and continuously monitor actual memory usage against this configured limit to catch any concerning trends before they become a serious problem.
Example

CONFIG SET maxmemory 4gb INFO memory | grep used_memory_human

Real-world example
A team running Redis on a server with eight gigabytes of total RAM sets maxmemory to six gigabytes, leaving comfortable headroom for the operating system while still giving Redis a generous, safely bounded amount of memory to work with.
Likely follow-ups
  • How much headroom should typically be left for the operating system and other processes?
  • What happens if maxmemory is set too close to the server's actual total available memory?
Related topics