Skip to content

Tune Redis Memory

Key idea:

Set maxmemory = 75 % of server RAM and maxmemory-policy = allkeys-lru (or volatile-lru if you rely on TTLs). Watch used_memory_rss / used_memory in INFO — a ratio > 1.5 = fragmentation, run MEMORY PURGE. MEMORY USAGE shows the size of a specific key. The biggest memory hogs are usually large hashes and sets without TTL.

Below: details, example, related terms, FAQ.

Check your site →

Details

  • maxmemory-policy: allkeys-lru (default for cache), volatile-lru (mixed cache+store)
  • MEMORY DOCTOR gives recommendations straight from Redis
  • Fragmentation: jemalloc usually copes, but after a mass DEL it can hit 2×
  • redis-cli --bigkeys scans and lists top keys by size
  • Active defragmentation: activedefrag yes in config

Example

# Quick memory audit
$ redis-cli --bigkeys

# top-10 keys by size
$ redis-cli --memkeys --memkeys-samples 100

# Check one key
$ redis-cli MEMORY USAGE sessions:user:1234
(integer) 2048

# Rebalance/defrag
$ redis-cli CONFIG SET activedefrag yes
$ redis-cli MEMORY PURGE

Related

Understanding Redis Memory Management

Redis is an in-memory data structure store, which means managing memory effectively is crucial for optimal performance. Understanding how Redis allocates and manages memory can help you tune your setup for better efficiency.

Redis uses a memory allocator to manage its memory. The default allocator is jemalloc, which is designed for high performance in multi-threaded applications. However, you can also configure Redis to use other allocators like libc or tcmalloc. The choice of allocator can significantly impact memory usage and fragmentation.

To monitor memory usage, use the INFO memory command. This command provides insights into memory fragmentation, total allocated memory, and peak memory usage. Pay attention to the used_memory, used_memory_rss, and mem_fragmentation_ratio metrics. A high fragmentation ratio (greater than 1.5) indicates that Redis is using more memory than necessary, which can be mitigated by using the MEMORY PURGE command to reclaim memory.

Additionally, consider using the maxmemory directive in your configuration to limit Redis memory usage. Setting maxmemory to 75% of your server's total RAM is a common practice. This prevents Redis from consuming all available memory, which could lead to system instability.

Practical Commands for Tuning Redis Memory

Tuning Redis memory involves specific commands and configurations that can help optimize memory usage and performance. Here are some practical commands you can use:

  • Set maxmemory: To limit the memory Redis can use, add the following line to your redis.conf file:
maxmemory 75% of your_server_RAM
  • Set maxmemory-policy: Choose a memory eviction policy based on your application's needs. For example, to use the LRU (Least Recently Used) policy for all keys:
maxmemory-policy allkeys-lru
  • Monitor Memory Usage: Use the following command to check your Redis memory usage:
INFO memory
  • Identify Large Keys: To find out how much memory a specific key is using, use:
MEMORY USAGE your_key_name
  • Purge Fragmented Memory: If you notice high fragmentation, run:
MEMORY PURGE

These commands will help you tune Redis memory effectively. Remember to monitor your server’s performance regularly to adjust configurations as needed.

Common Memory Management Issues in Redis

When tuning Redis memory, several common issues can arise that may affect performance and efficiency. Understanding these issues can help you proactively address them.

1. Memory Fragmentation: This occurs when Redis allocates memory in a way that leads to inefficient use of available space. You can identify fragmentation by checking the mem_fragmentation_ratio in the output of INFO memory. If the ratio exceeds 1.5, consider running MEMORY PURGE to reclaim fragmented memory.

2. Large Keys: Keys that store large hashes or sets without TTLs can consume excessive memory. Use MEMORY USAGE your_key_name to identify memory-heavy keys. Consider restructuring your data model to break down large keys or implementing TTLs where appropriate.

3. Eviction Policy Misconfiguration: Choosing the wrong eviction policy can lead to unexpected behavior. For instance, if you set maxmemory-policy volatile-lru but do not use TTLs, Redis may not evict keys as intended. Ensure that your policy aligns with your data usage patterns.

4. Overcommitting Memory: Setting maxmemory too high can lead to out-of-memory errors. Always set maxmemory to a value that allows for system stability, typically around 75% of total RAM.

By being aware of these common issues, you can better manage Redis memory and optimize your Redis instance for performance.

Score 0–100Unified site health score
SSL + SecuritySecurity and certificate status
PerformanceResponse speed and caching
SEO Signalsrobots.txt, sitemap, canonicals

Why teams trust us

100
point scale
SSL
SSL + HTTP headers
10+
scoring criteria
Free
no signup

How it works

1

Enter site URL

2

Analyse 10+ factors

3

Get overall score

What is Health Score?

Health Score is a comprehensive assessment of site technical health across 20+ parameters: SSL, security headers, response speed, SEO technical factors, and availability.

Comprehensive Score

20+ parameters in one number: SSL, headers, speed, SEO technical factors.

Detailed Breakdown

Each parameter with explanation — what is checked, what was found, how to fix.

Score Trends

Compare Health Score at different dates — see progress or regression.

Health Monitoring

Set up automated Health Score checks and get notified when the score drops.

Who uses this

Developers

quick pre-release audit

SEO

technical baseline score

Marketers

client site check

Security

header security audit

Common Mistakes

Ignoring red parametersA red parameter is a critical issue. Start fixing those, not the yellow ones.
Only checking homepageIssues may exist on subpages. Check key sections and landing pages.
Not re-checking after fixAfter each fix, rerun the check and verify the score improved.
Treating 80+ as good enoughAim for 95+. Every red item is a risk to SEO or security.

Best Practices

Fix by priorityRed > yellow > blue. Critical issues first.
Check regularlyWeekly Health Score check helps catch degradation before it affects SEO.
Use monitoringConnect an automated HTTP monitor — it will be the first to notice downtime.
Compare with competitorsCheck the Health Score of your nearest competitor — a great benchmark for prioritization.

Get more with a free account

Health Score check history and real-time site health monitoring.

Sign up free

Learn more

Frequently Asked Questions

When switch allkeys-lru → allkeys-lfu?

When your workload has a clear hot/cold partition (some keys read forever, others rarely). LFU wins for classic skewed workload.

Redis in production without persistence?

Fine for pure cache (session, counter). If the data cannot be regenerated, enable AOF everysec.

Sharding or Cluster?

Redis Cluster — built-in sharding (up to 1000 nodes). For < 100 GB sentinel + application-level sharding is more common.

Try the live tool that powered this guide

Free plan — 10 monitors, checks every 5 min, no card required. Upgrade for 1-minute interval and multi-region monitoring.