Linux

Modify redis.conf to Increase Max Cache

To increase the maximum cache size for Redis Server, you need to adjust the memory limit settings either in the Redis configuration file or via command line. Below is a detailed guide: 

1. Modify redis.conf to Increase Max Cache

Step 1: Open the Redis configuration file

Typical locations:

/etc/redis/redis.conf

# or

/etc/redis.conf

Step 2: Find and edit the following line:

# maxmemory <bytes>

Step 3: Uncomment and set the desired value, for example:

maxmemory 2gb

Redis supports units like kb, mb, and gb.

Step 4: (Recommended) Set a memory eviction policy:

maxmemory-policy allkeys-lru

Common policies:

  • noeviction: Don’t evict anything (default)

  • allkeys-lru: Evict least recently used keys

  • volatile-lru: Evict LRU keys with an expire set

  • allkeys-random: Evict random keys

  • volatile-ttl: Evict keys with the nearest expiration


2. Set Temporarily via Redis CLI

To test or apply settings without editing the config file:

redis-cli CONFIG SET maxmemory 2gb
redis-cli CONFIG SET maxmemory-policy allkeys-lru

⚠️ Note: These changes are temporary and will be lost after a Redis restart. Use the config file to make them permanent.


3. Restart Redis to Apply Config File Changes

sudo systemctl restart redis

# or

sudo service redis restart

4. Verify Current Redis Memory Settings

You can confirm the settings with:

redis-cli INFO memory
redis-cli CONFIG GET maxmemory
redis-cli CONFIG GET maxmemory-policy

Optional: Docker Users

If you are running Redis via Docker and need help updating the memory limits in docker-compose.yml or with the command override, just let me know and I’ll provide Docker-specific instructions.


Let me know how much memory you'd like to allocate (e.g., 4GB, 8GB), and I can help tailor the config.