Redis is fast because it keeps everything in RAM. That same strength turns into a problem on a 1 GB or 2 GB VPS, where one hungry cache can starve PHP, MySQL, and the web server until the kernel starts killing processes. Learning how to reduce Redis memory usage is mostly about setting a hard ceiling, choosing what gets thrown away first, and deleting data you no longer need. The steps below work on any Linux VPS running Redis 6 or 7, and most of them take effect with a single config change and a restart.
Why Redis Eats RAM on a Small VPS
By default, Redis has no memory limit at all. It keeps accepting keys until the operating system runs out of RAM, and on a small VPS that point arrives fast. A WordPress site with object caching is a common trigger: every page, query result, and transient lands in Redis, and nothing expires unless a plugin sets a TTL. Add a second app or a queue that stores job payloads, and the dataset grows every day without anyone noticing.
The first sign is usually vague. Pages slow down, SSH feels laggy, and then a process dies. Check dmesg for “Out of memory” lines and you will often find the kernel killed MySQL or PHP-FPM while Redis kept growing. That is the pattern to fix: Redis should never be allowed to take memory other services need to stay alive. If you have not yet traced which process is responsible, our guide on how to find which process is eating your VPS RAM shows the exact commands.
Check How Much Memory Redis Is Actually Using
Guessing wastes time. Run redis-cli INFO memory and look at three numbers: used_memory_human, used_memory_peak_human, and used_memory_dataset. The peak tells you the worst case your VPS has already survived. Compare used_memory_dataset with used_memory_human: a big gap means fragmentation or overhead, not real data, and points at a different fix than simply deleting keys.
Also check how many keys exist with redis-cli DBSIZE and sample the largest ones with redis-cli --bigkeys. On a WordPress site, a few thousand transients with no expiry are normal. Hundreds of thousands of keys on a 1 GB box means something is caching without limits. Keep an eye on the numbers over a week with htop and Glances so you can see whether usage climbs steadily or spikes at certain hours.
Set a maxmemory Limit Before Redis Takes Everything
The single most effective change is the redis maxmemory setting. It caps how much RAM Redis may use, and once the cap is hit, Redis stops growing and starts evicting keys instead. On a 1 GB VPS, leave at least half the RAM for the rest of the system and set Redis to 128 MB or 256 MB. On a 2 GB VPS, 256 MB to 512 MB is a reasonable range for a cache.
Edit /etc/redis/redis.conf and set:
maxmemory 256mb
maxmemory-policy allkeys-lru
Then restart Redis with sudo systemctl restart redis and confirm with redis-cli CONFIG GET maxmemory. You can also set it live without a restart using redis-cli CONFIG SET maxmemory 256mb, but write it into the config file too, or the next restart will drop the limit. Redis is only one of several services competing for RAM on a small box, so pair this with the same discipline elsewhere: our guide on how to tune MariaDB 11.x for a low-memory VPS applies the same idea to your database.
Pick an Eviction Policy to Reduce Redis Memory Usage
The redis eviction policy decides which keys Redis deletes when memory hits the cap. The default, noeviction, is the worst choice for a cache: instead of deleting old keys, Redis starts returning errors on every write, and your site breaks. For a cache, you want an LRU policy that removes the least recently used keys first.
- allkeys-lru: evict the least recently used key from any key. Best default for a general cache.
- volatile-lru: evict only keys that have an expiry set. Use it if some keys must never disappear.
- allkeys-lfu: evict the least frequently used key. Better than LRU when a small set of keys gets most of the traffic.
- volatile-ttl: evict the key with the shortest remaining TTL. Useful when your data has clear lifetimes.
For WordPress object caching, allkeys-lru is the safe starting point because every cached item can be rebuilt from the database. If Redis also stores sessions or queues, keep those in a separate Redis database or a second instance with noeviction, so eviction never deletes a login session or a pending job. Mixing cache data and permanent data in one instance is the most common cause of mysterious eviction bugs.
Cut Waste: Expires, Key Names, and Data Structures
Practical redis memory optimization vps work starts with storing less, not buying more RAM. Three habits make the biggest difference.
First, give every cache key a TTL. A key without an expiry lives forever, and stale transients pile up for months. WordPress plugins sometimes store data with no TTL at all, so audit with redis-cli --scan --pattern '*transient*' and check how many keys have no expiry. Set a default TTL in your application where you can, and run a periodic cleanup for keys that should have expired.
Second, shorten key names. Redis stores the key string with every value, so a 60-character key prefix repeated a million times costs real memory. Use short, consistent prefixes like wp:post:123 instead of long descriptive names. The same logic applies to hash field names.
Third, use hashes for small objects. Storing a user record as one hash with several fields uses far less memory than storing each field as a separate key, because Redis encodes small hashes in a compact format. The hash-max-listpack-entries setting controls that threshold; the default of 128 is fine for most cases. Raising it too far backfires, because one huge hash becomes slow to read and write.
On a redis low ram vps, every megabyte counts elsewhere too. If your system has already started swapping, read our guide on how to create a swap file on a low-RAM VPS and when it helps before you treat swap as a fix: swap keeps the server alive, but Redis on swap is slow Redis.
Turn Off Persistence You Do Not Need
Redis saves data to disk with RDB snapshots and the append-only file (AOF). Both cost memory and CPU, and a pure cache does not need either: if Redis restarts, the cache rebuilds itself from the database. Disabling persistence frees the memory Redis reserves for background saves and removes the fork that can spike RAM usage on a small VPS.
In redis.conf, comment out the save lines and set appendonly no. Restart Redis and check that no dump file is being written. The tradeoff is real: after a restart, the cache starts empty and the first requests after a reboot hit the database directly, so expect a brief slowdown. For a cache-only setup, that is a fair trade. Keep persistence on if Redis stores anything you cannot rebuild, such as sessions, queues, or rate-limit counters.
When Tuning Is Not Enough
Some workloads simply need more room. If you have set a sensible maxmemory limit, picked allkeys-lru, cleaned up stale keys, and Redis still evicts keys constantly, the cache is too small for the working set. At that point the options are to shrink what you cache, move Redis to its own small VPS, or add RAM. A separate Redis instance is cheap and isolates the cache from your web server, so a runaway cache can no longer kill PHP or MySQL.
Before you spend money, confirm the cache is actually helping. A WordPress site with Redis object caching should show fewer database queries per page, and our guide on how to speed up WordPress with Redis object caching on your VPS explains how to set it up and measure it. If hit rates are low, you may be caching data nobody reads twice, and trimming what gets cached buys more than a RAM upgrade. Start with a 256 MB maxmemory cap and allkeys-lru, watch eviction counts with INFO stats for a week, and raise the cap only if evicted keys stay high after cleanup.