Home » wp-content » cache » Allowed Memory Size Exhausted in object-cache.php: Redis Fix

Allowed Memory Size Exhausted in object-cache.php: Redis Fix

Saving a synced pattern or a template part fails the first time and works on the second click. The PHP log shows Allowed memory size of 134217728 bytes exhausted inside wp-content/object-cache.php. If that is your site, the Redis object cache is usually the messenger, not the cause.

This exact case came up this week in the Redis Object Cache support forum: WordPress 7.1.4, the default 128MB PHP limit, a stack trace ending in serialize(), and a second fatal error in class-wpdb.php half a minute later. Both errors mean the same thing. One request is holding too much data in memory.

More memory stops the errors today. The real fix is finding the oversized cache value and making it smaller.


The block editor saves through the REST API. In the browser console you will see a line like /wp-json/wp/v2/blocks/97099?_locale=user 500 (Internal Server Error), and the PHP or PHP-FPM error log has the fatal error at the same time.

That detail matters. WordPress raises memory to WP_MAX_MEMORY_LIMIT (256M by default) for admin screens through wp_raise_memory_limit(), but a REST request does not load through wp-admin/admin.php, so it does not get that boost. It runs with WP_MEMORY_LIMIT and whatever PHP’s memory_limit allows.

That is why the editor opens fine and only the save fails. I explain the two constants in more detail in WP_MEMORY_LIMIT vs WP_MAX_MEMORY_LIMIT.

Back up wp-config.php first. Then add this line above /* That's all, stop editing! */:

define( 'WP_MEMORY_LIMIT', '256M' );
object cache php memory exhausted redis wp config 1 - Allowed Memory Size Exhausted in object-cache.php: Redis Fix
Where it goes in wp-config.php: above the “That’s all, stop editing!” line

WordPress can only raise the limit if the host lets PHP change memory_limit at runtime. If saves still fail and the log still says 134217728 bytes, the host enforces the cap, so raise memory_limit in php.ini, the PHP-FPM pool or your control panel instead.

Treat this as a bandage. If saving a 1KB block needs more than 128MB, something else in that request is huge, and it will keep growing.


The plugin author’s answer in that thread was to look for large keys. redis-cli has a scan built in for exactly that:

redis-cli --bigkeys
redis-cli --memkeys

--bigkeys reports the biggest key of each data type, and --memkeys does the same based on memory use. If Redis needs a password or lives on another host, add -h, -p and -a.

Then check single suspects. The alloptions key is the first one I look at:

redis-cli --scan --pattern '*alloptions*'
redis-cli MEMORY USAGE "paste-the-key-name-here"

MEMORY USAGE returns the size in bytes. A single key in the megabytes is enough to push a 128MB request over the edge, because PHP holds the full array and its serialized copy at the same moment.

💡 Set a unique WP_REDIS_PREFIX per site. Every key then starts with it, which makes it easy to tell sites apart when several share one Redis server.

The usual heavyweight is alloptions. WordPress loads every autoloaded option as one array, and the object cache stores that array as one value. Whenever any autoloaded option changes, the whole value is serialized and written back to Redis.

Back up the database before you change anything. If your backup plugin chokes on it, use the WP-CLI export from WordPress Backup Stuck on the Database? Then measure:

wp db export before-autoload.sql
wp option list --autoload=on --format=total_bytes
wp option list --autoload=on --fields=option_name,size_bytes | sort -n -k 2 | tail -20

The second command prints one number: the total size of autoloaded options in bytes. Since WordPress 6.6, Site Health shows “Autoloaded options could affect performance” when that total passes 800 KB.

See also  WordPress Backup Stuck on the Database? Export It With WP-CLI

The third command lists the 20 biggest autoloaded options, largest at the bottom. If you prefer SQL, this query covers all the autoload values WordPress uses since 6.6:

SELECT option_name, LENGTH(option_value) AS bytes, autoload
FROM wp_options
WHERE autoload IN ('yes', 'on', 'auto-on', 'auto')
ORDER BY bytes DESC
LIMIT 20;

💡 Replace wp_ with your table prefix.

Now read the names. Settings left behind by plugins you deleted can go. Options that a live plugin only needs on its own settings page can stop autoloading:

wp option set-autoload some_big_option off
wp cache flush

WP-CLI should reply with Success: Updated autoload value for 'some_big_option' option. The flush makes WordPress rebuild alloptions in Redis without it. Leave core options such as siteurl, home, active_plugins and cron alone.

WordPress 6.6 stopped autoloading new options over 150,000 bytes by default (see the Options API dev note). Options created before that, or saved with an explicit autoload flag, still load on every request, which is why old sites carry the biggest arrays.


Sometimes the big key is not alloptions but a plugin’s own cache group, like stats or logs. The group name shows up in the key names you found in Step 3. You can keep that group out of Redis and cap how long keys live:

define( 'WP_REDIS_IGNORED_GROUPS', array( 'some_plugin_group' ) );
define( 'WP_REDIS_MAXTTL', 86400 );
object cache php memory exhausted redis wp config 2 - Allowed Memory Size Exhausted in object-cache.php: Redis Fix
Where it goes in wp-config.php: above the “That’s all, stop editing!” line

According to the Redis Object Cache README, ignored groups are not cached between requests, and WP_REDIS_MAXTTL is the maximum time-to-live of cache keys. Set in seconds, 86400 means nothing sits in Redis for more than a day.

If saves break across the whole site and you need a way out right now, define( 'WP_REDIS_DISABLED', true ); bypasses the object cache without deleting the drop-in. Run wp redis status afterwards to confirm. If Redis itself is unreachable, that is a different error, covered in Error Establishing a Redis Connection.

In OpenPanel, Redis runs as its own service under Cache → Redis, and WordPress connects to host redis on port 6379, as shown in the OpenPanel Redis guide. Its Edit limits button sets the Redis container memory. That helps when Redis fills up, but it does nothing for the PHP fatal error above, and changing it restarts Redis and empties the cache. Stock cPanel has no Redis screen, so where Redis runs and how much memory it gets depends on what your host added.


TL;DR: A memory fatal error in object-cache.php on save means one request is moving a very large cached value. Raise WP_MEMORY_LIMIT to 256M to stop the errors, then use redis-cli --bigkeys and wp option list --autoload=on to find what is big, turn off autoload for options that do not need it, and flush the cache. As of 2026-11-16, the only advice from the plugin author in that thread is to find the large keys, so start there.

Was this post helpful?

Leave a Comment

I enjoy constructive responses and professional comments to my posts, and invite anyone to comment or link to my site.

Recommended