A proper wordpress redis object cache setup stops WordPress from repeating the same expensive database queries on every uncached page load. By storing query results, options, and transients in memory, Redis cuts database CPU usage and speeds up dynamic pages like WooCommerce carts and WP-Admin. This guide walks through when Redis helps, how to install and configure it cleanly, how to measure the win, and how to avoid the WooCommerce and page-caching traps that break production sites.
Quick answer
- Install the Redis server and the PHP
phpredisextension on your host. - Define
WP_REDIS_PREFIXand connection constants inwp-config.phpbefore enabling the drop-in. - Install the Redis Object Cache plugin and enable
object-cache.phpvia WP-CLI. - Set Redis
maxmemory-policytoallkeys-lruso full memory never crashes writes. - Verify hit rates with
redis-cli info statsand Query Monitor, and exclude WooCommerce session keys from aggressive flushing.
When a persistent object cache actually helps
By default, WordPress has an in-memory object cache (WP_Object_Cache) that only lives for a single PHP request. Once the page finishes rendering, that cache disappears. A persistent object cache like Redis keeps those cached objects in RAM across requests.
On production builds I start by asking whether the site is mostly static or genuinely dynamic. If you run a brochure site behind Cloudflare APO or Nginx FastCGI page caching, anonymous visitors never hit PHP or MySQL anyway. Redis will not make a cached HTML page faster.
Redis delivers major gains when PHP must execute:
- WooCommerce stores with cart fragments, dynamic pricing, and checkout requests that bypass page caching.
- Membership, LMS, or intranet sites where most traffic is logged in.
- Heavy WP-Admin workflows, bulk imports, or complex
WP_Queryand ACF lookups. - High-traffic REST API or WPGraphQL endpoints powering a headless front end.
If your bottleneck is a bloated wp_options autoloaded payload or unindexed wp_postmeta queries, fix those first. Redis masks bad queries until the cache flushes, at which point a cache stampede can still take down MySQL.
Server prerequisites: Redis and phpredis
Before touching WordPress, you need the Redis server running and the PHP extension installed. I strongly recommend phpredis (the C extension) over pure-PHP clients like Predis because it is significantly faster and uses less memory.
On Ubuntu or Debian, install both and verify the service is active:
sudo apt update
sudo apt install redis-server php-redis
sudo systemctl enable --now redis-server
redis-cli ping
If redis-cli ping returns PONG, the daemon is listening on 127.0.0.1:6379. Next, configure Redis memory limits in /etc/redis/redis.conf so it never starves the OS or MySQL:
maxmemory 512mb
maxmemory-policy allkeys-lru
Restart Redis after editing the config (sudo systemctl restart redis-server). Using allkeys-lru tells Redis to evict the least recently used keys when it hits 512 MB. Without this, Redis defaults to noeviction and throws errors on every SET command once memory is full.
WordPress Redis object cache setup
Once Redis and phpredis are running, configure WordPress before dropping in the object cache file. This prevents key collisions if multiple sites share one Redis instance.
1. Add constants to wp-config.php
Add these constants to wp-config.php above the / That's all, stop editing! / line. Always set a unique WP_REDIS_PREFIX per site.
define( 'WP_REDIS_HOST', '127.0.0.1' );
define( 'WP_REDIS_PORT', 6379 );
define( 'WP_REDIS_DATABASE', 0 );
define( 'WP_REDIS_PREFIX', 'mysite_prod_' );
define( 'WP_REDIS_TIMEOUT', 1 );
define( 'WP_REDIS_READ_TIMEOUT', 1 );
Short timeouts (1 second) are critical. If Redis ever hangs, you want WordPress to fail fast and fall back to MySQL rather than locking up PHP-FPM workers for 30 seconds.
2. Install and enable the drop-in
Use WP-CLI to install the Redis Object Cache plugin and copy its object-cache.php drop-in into wp-content/:
wp plugin install redis-cache --activate
wp redis enable
wp redis status
You should see Status: Connected and Client: PhpRedis. If you are on a managed host that already provides object-cache.php as a must-use or drop-in file, do not overwrite it without checking their documentation.
Never share the sameWP_REDIS_PREFIXandWP_REDIS_DATABASEacross staging and production on the same server. Flushing the cache on staging will wipe production keys, or worse, serve staging options on the live site.
How to measure the win
Do not assume Redis is helping just because wp redis status says connected. Measure both the query reduction in WordPress and the hit ratio in Redis.
Check Query Monitor on an uncached request
Install Query Monitor on staging or test as a logged-in admin on production. Load a heavy page (such as the WooCommerce Shop page or WP-Admin Posts list) before and after enabling Redis.
Look at the Database Queries panel. You should see the total query count drop noticeably on the second load, and the Object Cache panel should report high hit percentages.
Check Redis hit/miss ratio via CLI
Run redis-cli info stats on the server to inspect keyspace_hits and keyspace_misses:
redis-cli info stats | grep -E "keyspace_hits|keyspace_misses|evicted_keys"
Calculate your hit rate as hits / (hits + misses). A healthy WordPress site typically settles above 85% to 90% after warming up. If evicted_keys is climbing rapidly, increase maxmemory in /etc/redis/redis.conf.
Pitfalls with WooCommerce and page caching
Redis is not a silver bullet, and WooCommerce introduces specific edge cases that trip up standard setups.
WooCommerce sessions and transients
WooCommerce stores customer sessions in wp_options or the woocommerce_sessions table, and relies heavily on transients for product lookups and shipping rates. When Redis is active, transients are stored in Redis instead of the database.
If you run wp cache flush or redis-cli flushall during a deployment, you can wipe active transients and force every concurrent shopper to regenerate expensive queries at once. Avoid flushing the entire Redis instance on deploy; instead, flush only specific groups or let TTLs expire naturally.
Page caching vs. object caching
Object caching does not replace page caching. Full-page caching (Nginx FastCGI, Varnish, or Cloudflare) serves complete HTML without invoking PHP. Object caching only speeds up PHP requests that miss the page cache.
Be careful with plugins that bundle both page caching and object caching into one interface. If a page cache plugin flushes the object cache every time a single post is updated, your Redis hit rate will plummet. Keep page cache invalidation targeted, and let Redis handle persistent object storage independently.
Oversized keys and memory bloat
Some plugins store massive serialized arrays in a single option or transient. Reading and unserializing a 5 MB object from Redis on every request can actually be slower than a targeted SQL query. If you spot slow object cache calls in Query Monitor, inspect large keys in Redis:
redis-cli --bigkeys
If a plugin is stuffing megabytes into a single transient, fix the plugin code or exclude that cache group from persistent storage using WP_REDIS_IGNORED_GROUPS in wp-config.php.
Checklist
- Confirm the site has uncached dynamic traffic (WooCommerce, logged-in users, or heavy admin/API usage) that will benefit from Redis.
- Install
redis-serverand the PHPphpredisextension, and verifyredis-cli pingreturnsPONG. - Set
maxmemoryandmaxmemory-policy allkeys-lruin/etc/redis/redis.conf. - Define
WP_REDIS_PREFIX,WP_REDIS_HOST,WP_REDIS_TIMEOUT, andWP_REDIS_READ_TIMEOUTinwp-config.php. - Enable the
object-cache.phpdrop-in withwp redis enableand confirmPhpRedisis active. - Verify database query drops in Query Monitor and check
keyspace_hitsvskeyspace_missesinredis-cli info stats. - Avoid running
flushallon deployments so you do not trigger a WooCommerce cache stampede.
Frequently asked questions
Does WordPress need Redis if I already use Cloudflare page caching?
If your site is mostly static and Cloudflare caches the HTML, anonymous visitors never hit PHP or MySQL, so Redis will not speed up those pages. However, Redis still speeds up WP-Admin, logged-in users, WooCommerce cart and checkout requests, and REST API calls that bypass the page cache.
What is the best Redis maxmemory-policy for WordPress?
Use allkeys-lru in /etc/redis/redis.conf. When Redis reaches its memory limit, allkeys-lru automatically evicts the least recently used keys to make room for new ones. The default noeviction policy causes Redis to reject new writes and throw errors once memory is full.
Can I use one Redis server for multiple WordPress sites?
Yes, as long as you isolate each site. Define a unique WP_REDIS_PREFIX in each site's wp-config.php, or assign each site a different WP_REDIS_DATABASE number. Never share the same prefix and database between staging and production.
Why did my WooCommerce site slow down after enabling Redis?
A slowdown usually happens when a plugin stores huge serialized arrays in a single transient or option, or when Redis is using a slow pure-PHP client instead of phpredis. Check Query Monitor for slow object cache calls and run redis-cli --bigkeys to spot oversized keys.
- Web Vitals (web.dev)Web Vitals (web.dev)
- Lighthouse overviewLighthouse overview
Drafted with AI assistance. Code targets current WordPress, WooCommerce and Next.js APIs; test changes on a staging site before production.