Skip to content

Deploying Redis object cache for WordPress in production

wp-redis, Redis Object Cache, and Object Cache Pro behave very differently under load. The decisions that matter — persistence, eviction, multisite scoping — are made at install, not after the first incident.

Your WooCommerce checkout is fine at 50 concurrent users and dies at 200, with MySQL pegged on wp_options autoload queries and get_option() calls that show up everywhere in the New Relic trace. You drop in a popular Redis object cache plugin from the wordpress.org repo, point it at a local Redis, and load testing now shows 4× throughput — until the Redis instance OOMs at 2 AM, evicts session data, and the morning support queue lights up with carts disappearing mid-checkout. The fix isn’t “more Redis”; it’s making four decisions correctly before the cache goes live.

What’s happening

WordPress core ships a non-persistent, in-process object cache that lives only for the duration of a single request. Every page load re-fetches options, postmeta, usermeta, and terms from MySQL. The drop-in pattern at wp-content/object-cache.php replaces that with a backend that persists across requests — Memcached or, far more commonly today, Redis.

There are three serious implementations in use:

  • wp-redis (Pantheon-maintained) — minimalist drop-in, no admin UI, uses PhpRedis directly. Fast, opinionated, no per-group invalidation. Good for single-purpose sites where you control the codebase.
  • Redis Object Cache (Till Krüss, free) — the most-installed option from wordpress.org. Pluggable backend (Predis, PhpRedis, Relay), admin UI, basic stats. Reasonable default for most production sites.
  • Object Cache Pro (Till Krüss, commercial) — the same author’s paid version. Adds connection pooling, async flushing, prefetching, advanced metrics, group-level invalidation, and (critically at scale) safer behavior on cache flush. WooCommerce officially recommends it for stores.

The plugin choice matters less than four decisions every deployment must make:

1. Persistence policy. Redis can be run as a pure cache (no AOF, no RDB) where data is ephemeral, or as a persistent store. For an object cache, the right answer is pure cache with maxmemory-policy allkeys-lru (or allkeys-lfu). Keeping persistence on for a cache means slow restarts, larger disks, and the surprise discovery that your cache contains stale data from three weeks ago.

2. Eviction policy. Default Redis maxmemory-policy is noeviction, which means Redis stops accepting writes when full. For an object cache that’s the worst possible default — every wp_cache_set call returns false and PHP falls back to MySQL, which is now under sudden load. Always set allkeys-lru or allkeys-lfu.

3. Multisite scoping. On a multisite network the same option key (siteurl, home, template) exists per-blog. Cache keys must include the blog ID prefix or every subsite reads the same cached value, with hilarious consequences. All three plugins handle this if WP_CACHE_KEY_SALT is set per-environment and the blog prefix is left at default — but only if you confirm it.

4. Connection model. PHP-FPM with 50 workers and one Redis connection per request creates connection storms. PhpRedis with persistent connections, or Object Cache Pro’s pooled connections, prevents this. The default Redis Object Cache config with Predis and non-persistent connections is a frequent root cause of “Redis works in dev, falls over in production.”

The “I added Redis and traffic doubled then crashed” pattern is almost always one of: noeviction policy, persistent connections off, or shared Redis instance also holding session data with no DB separation.

How to verify

Confirm the drop-in is loaded and the backend is responding:

# Is object-cache.php in place?
ls -la /home/wpuser/public_html/wp-content/object-cache.php

# What does WP see?
wp redis status
# OR for Object Cache Pro:
wp cache type

# Ping Redis directly
redis-cli -h 127.0.0.1 -p 6379 ping
# AUTH if you've set requirepass
redis-cli -h 127.0.0.1 -p 6379 -a "$REDIS_PASSWORD" ping

Inspect Redis memory state, eviction policy, and connected clients:

redis-cli INFO memory | grep -E "used_memory_human|maxmemory_human|maxmemory_policy|evicted_keys"
redis-cli CONFIG GET maxmemory-policy
redis-cli CLIENT LIST | wc -l

If evicted_keys is growing fast and used_memory_human is at maxmemory, your cache is thrashing — either the cache is undersized or you have unbounded growth (transients without expiry, cron entries, etc.).

Check hit ratio over a representative window:

redis-cli INFO stats | grep -E "keyspace_hits|keyspace_misses"
# Hit ratio = hits / (hits + misses). Below ~0.85 in steady state means a tuning problem.

For multisite, sanity check that subsite caches are not colliding:

redis-cli --scan --pattern "wp:options:*" | head -20
# You should see blog-ID-prefixed keys like wp:options:1:siteurl, wp:options:2:siteurl

If you only see wp:options:siteurl with no blog prefix, your multisite cache is sharing keys across the network — every subsite reads the same option values. This is the symptom of WP_CACHE_KEY_SALT unset and the drop-in not detecting MULTISITE.

The fix

The full deployment, end to end. This is what we install on every production WordPress that has earned a Redis cache.

Redis server config

/etc/redis/redis.conf (or the systemd-managed override file):

# Bind to localhost only — never expose Redis to the public network without TLS+AUTH
bind 127.0.0.1 ::1
protected-mode yes
port 6379

# Memory limit — set this to leave room for the OS and PHP-FPM
# On an 8 GB host, 2-3 GB for Redis is typical
maxmemory 2gb
maxmemory-policy allkeys-lru

# Persistence OFF for a pure object cache
# Comment out or remove save lines, disable AOF
save ""
appendonly no

# Connection limits
maxclients 10000
timeout 300
tcp-keepalive 60

# AUTH — set a strong password even on localhost-bound Redis
requirepass "REPLACE_WITH_LONG_RANDOM_SECRET"

# Disable dangerous commands in production
rename-command FLUSHDB ""
rename-command FLUSHALL ""
rename-command CONFIG "CONFIG_a8f3c2b1"   # randomize, document in runbook
rename-command DEBUG ""

# Logging
loglevel notice
logfile /var/log/redis/redis-server.log

Reload Redis:

systemctl restart redis-server
systemctl status redis-server

PhpRedis (preferred over Predis at scale)

Install via PECL or distribution package — never use Predis in production WP if you have a choice. PhpRedis is a C extension; Predis is pure PHP and 4-10× slower under load.

# AlmaLinux / RHEL with Remi
dnf install php82-php-pecl-redis

# Debian / Ubuntu
apt install php8.2-redis

# Verify
php -m | grep -i redis
# Should print: redis

If WooCommerce, BuddyBoss, LearnDash, or any multisite of meaningful traffic, Object Cache Pro is worth the line item. Install via Composer or upload the plugin zip you receive at purchase.

wp-config.php additions:

// --- Redis Object Cache Pro ---
define( 'WP_REDIS_CONFIG', [
    'token'      => 'YOUR_LICENSE_TOKEN_HERE',
    'host'       => '127.0.0.1',
    'port'       => 6379,
    'database'   => 0,
    'password'   => 'REPLACE_WITH_LONG_RANDOM_SECRET',
    'client'     => 'phpredis',
    'maxttl'     => 86400 * 7,    // 7 days
    'timeout'    => 0.5,
    'read_timeout' => 0.5,
    'split_alloptions' => true,   // critical for sites with bloated wp_options
    'prefetch'   => true,
    'compression' => 'zstd',
    'serializer' => 'igbinary',
    'async_flush' => true,
    'strict'     => true,
    'debug'      => false,
] );

define( 'WP_REDIS_DISABLED', false );
define( 'WP_CACHE', true );
define( 'WP_CACHE_KEY_SALT', 'prod-acme:' );  // unique per environment

Then drop the object-cache.php from the plugin into wp-content/:

wp redis enable
wp cache flush
wp cache type   # should print 'Redis (Object Cache Pro)'

Free Redis Object Cache (Till Krüss) — equivalent setup

If you’re not buying the Pro version, the free plugin from wordpress.org is fine for non-commerce sites. wp-config.php:

define( 'WP_REDIS_HOST', '127.0.0.1' );
define( 'WP_REDIS_PORT', 6379 );
define( 'WP_REDIS_PASSWORD', 'REPLACE_WITH_LONG_RANDOM_SECRET' );
define( 'WP_REDIS_DATABASE', 0 );
define( 'WP_REDIS_CLIENT', 'phpredis' );
define( 'WP_REDIS_TIMEOUT', 1 );
define( 'WP_REDIS_READ_TIMEOUT', 1 );
define( 'WP_REDIS_MAXTTL', 86400 * 7 );
define( 'WP_REDIS_PREFIX', 'wp:' );
define( 'WP_CACHE_KEY_SALT', 'prod-acme:' );
define( 'WP_CACHE', true );

// Persistent connections — non-negotiable in production
define( 'WP_REDIS_IGBINARY', true );

Activate via WP-CLI:

wp plugin install redis-cache --activate
wp redis enable
wp redis status

Multisite scoping

On multisite, the drop-in needs to see MULTISITE defined and the blog ID will be appended automatically. What you must control:

  • WP_CACHE_KEY_SALT should be environment-scoped (prod vs staging vs dev), not blog-scoped.
  • The Redis database number should be different per environment if you’re sharing a Redis cluster across staging and prod ('database' => 1 for staging). Better, use a separate Redis instance entirely.
  • define('WP_REDIS_MAXTTL', ...) applies network-wide. Set it conservatively (7 days) so that orphaned cache entries from deleted subsites don’t accumulate.

After flipping multisite to Redis, walk the network and warm the cache:

for id in $(wp site list --field=blog_id); do
  url=$(wp site url "$id")
  wp cache flush --url="$url"
  curl -sI "$url" > /dev/null  # touch the homepage to warm
done

Failover behavior

When Redis goes away mid-request — host crash, network partition, OOM kill — both free Redis Object Cache and Object Cache Pro fail over gracefully to the in-process cache and continue serving the request from MySQL. The visible effect is a sudden TTFB increase and MySQL load spike, not a 500 error.

What you must verify in staging before production: kill Redis with systemctl stop redis-server while running synthetic checkout traffic. The site should slow down, not break. If you see PHP errors, your drop-in is misconfigured (likely Predis with non-persistent connections that throw on CONNECTION_REFUSED).

Monitoring hooks

The metrics worth alerting on:

  • redis.used_memory > 85% of maxmemory for 10 minutes
  • redis.evicted_keys rate > 0 sustained (any eviction outside of normal LRU churn is a sign of undersized cache)
  • redis.connected_clients > 80% of maxclients
  • redis.rejected_connections > 0 (Redis ran out of connection slots)
  • WP-CLI wp cache type returning the non-Redis backend (drop-in fell back, you don’t want to discover this from a user)

Patterns that bite

A handful of WordPress-specific issues we hit on inherited sites:

  • alloptions bloat. Plugins that store large serialized arrays in wp_options with autoload=yes blow up the cached alloptions blob, which lives in a single Redis key. Object Cache Pro’s split_alloptions => true mitigates this; for the free plugin, audit autoloaded options and disable autoload on anything >50KB.
  • Transients in Redis vs DB. With a persistent object cache, transients should go to Redis automatically and never touch wp_options. If wp_options still grows with _transient_* rows, the drop-in is not active — re-check wp redis status.
  • WooCommerce session storage. WooCommerce stores sessions in wp_sessions (DB), not the object cache, by default. If you’re seeing session-related Redis pressure, you have a third-party plugin pushing sessions to Redis — that’s separate concern and should ideally live on a separate Redis database number or instance.

Stack Harbor runs Redis-backed object caching for WordPress under the enterprise WordPress hosting operating model, including Object Cache Pro licensing, monitoring, and the failover drills that make sure it stays graceful when Redis hiccups. If your store is dying under load and the Redis dashboard isn’t telling you why, we can audit the stack.