Redis Frequent Evictions

High rates of key evictions due to the server running out of memory, potentially leading to data loss if not managed properly.
  1. Check Memory Usage and Settings: Start by checking the memory usage and the configuration settings of your Redis instance. Use the command INFO memory to get memory usage details and CONFIG GET maxmemory* to check the memory limits set on your Redis server.
  2. Analyze Evictions and Key Expiry: Use the command INFO stats to check the evicted_keys metric which tells you the number of evictions. This will help you understand the rate at which keys are being evicted.
  3. Identify Large Keys: Use the command MEMORY USAGE <key> for a few keys to identify if there are any unusually large keys that might be causing memory issues. Alternatively, use a script or tool like redis-cli --bigkeys to automatically find the biggest keys in your database.
  4. Review and Adjust Eviction Policy: Check your current eviction policy with CONFIG GET maxmemory-policy and consider if it's appropriate for your use case. If necessary, adjust the policy with CONFIG SET maxmemory-policy <policy_name> choosing from options like noeviction, allkeys-lru, volatile-lru, allkeys-random, volatile-random, volatile-ttl depending on your needs.
  5. Monitor Key Expiry Settings: Ensure that keys that should expire are correctly set with TTLs. You can check if a key has an expiry with TTL <key> and set one with EXPIRE <key> <seconds> if needed.
  6. Optimize Data Storage: If specific data types are causing memory bloat, consider optimizing them. For example, use hashes for storing objects instead of flat strings.
  7. Scale Your Redis: If the issue persists and is not related to a specific configuration or data type issue, you may need to scale your Redis instance either by increasing the memory available to Redis or by scaling out using Redis Cluster if your setup and Redis version support it.

Master

Redis

in Minutes — Grab the Ultimate Cheatsheet

(Perfect for DevOps & SREs)

Most-used commands
Real-world configs/examples
Handy troubleshooting shortcuts
Your email is safe with us. No spam, ever.

Thankyou for your submission

We have sent the cheatsheet on your email!
Oops! Something went wrong while submitting the form.

Redis

Cheatsheet

(Perfect for DevOps & SREs)

Most-used commands
Your email is safe with us. No spam, ever.

Thankyou for your submission

We have sent the cheatsheet on your email!
Oops! Something went wrong while submitting the form.

MORE ISSUES

Made with ❤️ in Bangalore & San Francisco 🏢

Doctor Droid