Why Redis Object Cache Matters for WordPress Performance
Setting up Redis object cache for WordPress is one of the most effective performance optimizations available to site administrators. Every time a visitor loads a page, PHP executes dozens of database queries. Menu structure, widget content, options table lookups, user session data, transients — they all hit MySQL on every single request. On a site with 50+ plugins, that number can easily exceed 200 queries per page load.
Redis eliminates this bottleneck by storing frequently accessed data in RAM. Instead of making round trips to MySQL, WordPress reads from an in-memory key-value store that responds in microseconds rather than milliseconds. The difference is measurable and significant: typical WordPress sites see a 30-50% reduction in page generation time after enabling Redis object caching.
This guide walks you through the complete Redis setup process: installing Redis on your server, configuring WordPress to use it, verifying the connection, monitoring cache performance, and benchmarking before and after results. Every command is tested and every config snippet is production-ready.
Prerequisites: What You Need Before Starting
Before installing Redis, confirm you have the following:
- Root or sudo access to your server (SSH required)
- WordPress 5.0+ running on PHP 7.4 or higher
- A VPS or dedicated server — shared hosting typically does not allow Redis installation
- WP-CLI installed (optional but recommended for verification)
- At least 512MB free RAM — Redis stores everything in memory
If you are on managed WordPress hosting like Cloudways, Kinsta, or WP Engine, Redis may already be available as a one-click addon. Check your hosting panel before proceeding with manual installation.
Note: This guide covers Ubuntu/Debian servers. CentOS/RHEL users should substitute
aptcommands withyumordnfequivalents.
Step 1: Install Redis Server on Ubuntu/Debian
Start by updating your package index and installing Redis from the default repositories:
Configure Redis for WordPress
Open the Redis configuration file and make these changes for a WordPress-optimized setup:
Restart Redis to apply the changes and verify the password works:
Step 2: Install the PHP Redis Extension
WordPress communicates with Redis through PHP. You need the phpredis extension installed for your specific PHP version.
Step 3: Configure wp-config.php for Redis
Now connect WordPress to your Redis instance. Open your wp-config.php file (see our guide on essential wp-config.php settings every developer should know) and add these constants above the line that says /* That's all, stop editing! */:
Understanding Each Constant
| Constant | Purpose | Default |
|---|---|---|
WP_REDIS_HOST |
Redis server address | 127.0.0.1 |
WP_REDIS_PORT |
Redis server port | 6379 |
WP_REDIS_PASSWORD |
Authentication password | none |
WP_REDIS_DATABASE |
Redis database index (0-15) | 0 |
WP_REDIS_TIMEOUT |
Connection timeout in seconds | 1 |
WP_REDIS_READ_TIMEOUT |
Read timeout in seconds | 1 |
WP_REDIS_PREFIX |
Key prefix for multi-site isolation | wp_ |
The timeout values of 1 second are intentionally conservative. If Redis fails to respond within 1 second, WordPress falls back to MySQL automatically. This prevents Redis outages from taking down your site.
Step 4: Install the Object Cache Drop-In
WordPress needs an object-cache.php file in the wp-content directory to use Redis as its object cache backend. The most reliable way to install this is through the Redis Object Cache plugin by Till Kruss.
Option A: Install via WP-CLI (Recommended)
Option B: Install via WordPress Admin
- Go to Plugins > Add New in your WordPress dashboard
- Search for “Redis Object Cache” by Till Kruss
- Install and activate the plugin
- Navigate to Settings > Redis
- Click Enable Object Cache
Option C: Manual Drop-In (Advanced)
If you prefer not to use a plugin, you can use a standalone object-cache.php drop-in. The WordPress Starter Cache module or Starter Cache files from the developer community work well. However, the Redis Object Cache plugin provides monitoring and diagnostics that make troubleshooting significantly easier.
After installation, the expected status output should look like this:
Step 5: Verify Redis Is Working
Installation is only half the battle. You need to confirm that WordPress is actually using Redis and that the cache hit ratio is healthy.
Press Ctrl+C to stop the MONITOR command. You should see GET and SET commands corresponding to WordPress cache groups like options, posts, terms, and transient.
Check via WordPress Admin
Navigate to Settings > Redis in your WordPress dashboard. The status page shows:
- Status: Connected or Not Connected
- Hit Ratio: Percentage of cache hits (target: 85%+)
- Bytes Used: Current memory consumption
- Calls: Total cache operations since last flush
Step 6: Benchmark Before and After
Numbers matter more than feelings. Run these benchmarks both before enabling Redis (with the drop-in disabled) and after to quantify the improvement.
Method 1: Query Monitor Plugin
Install the Query Monitor plugin and check the database queries panel. Compare total query count and execution time before and after Redis.
| Metric | Before Redis | After Redis | Improvement |
|---|---|---|---|
| Database Queries | 187 | 42 | 77% fewer |
| Query Time | 0.084s | 0.019s | 77% faster |
| Page Generation | 0.42s | 0.21s | 50% faster |
| Memory Usage | 42MB | 38MB | 10% less |
These numbers are from a production WordPress site running WooCommerce with 30 active plugins. Your results will vary based on your plugin stack and hosting configuration.
Method 2 and 3: WP-CLI and Apache Bench
Compare the “Time per request” metric before and after enabling Redis.
Step 7: Monitor Redis in Production
Redis is a “set and forget” service for most WordPress sites, but monitoring prevents surprises. Here are the key metrics to watch.
Key Metrics to Watch
| Metric | Healthy Range | Action if Outside Range |
|---|---|---|
| Hit Ratio | 85-99% | Below 85%: check ignored groups or stale cache |
| Memory Usage | Below maxmemory | Increase maxmemory or reduce prefix scope |
| Evictions | Low or zero | High evictions: increase memory limit |
| Connected Clients | Matches PHP workers | Too high: check for connection leaks |
Troubleshooting Common Redis Issues
Even a straightforward Redis setup can hit snags. Here are the most common issues and their fixes.
Issue 1: “Connection Refused” Error
If Redis is bound to a specific IP and WordPress connects from a different one, update the bind directive or change WP_REDIS_HOST in wp-config.php.
Issue 2: Authentication Failed
Ensure there are no trailing spaces or encoding issues in the password string. Copy-pasting from a rich text editor can introduce invisible characters.
Issue 3: Cache Not Being Used (0% Hit Ratio)
This usually means the object-cache.php drop-in is missing or outdated:
Issue 4: Memory Exceeded
Issue 5: Stale Data After Updates
If you update posts or settings and the old version keeps appearing, flush the Redis cache:
Advanced Configuration: Redis for Multisite
On WordPress Multisite installations, each subsite should use a unique Redis prefix to prevent cache collisions between sites.
The prefix approach is simpler and works well for most Multisite networks. The separate database approach provides stronger isolation but limits you to 16 sites (Redis databases 0-15).
Redis for WooCommerce Sites
WooCommerce sites benefit enormously from Redis because the cart, session, and product query data are all cacheable. However, you should exclude cart-related transients from persistent caching to prevent stale cart data. The WooCommerce ignored groups configuration is included in the multisite snippet above.
Redis vs. Memcached: Which Should You Choose?
Both are in-memory caching solutions, but Redis has several advantages for WordPress:
| Feature | Redis | Memcached |
|---|---|---|
| Data Structures | Strings, lists, sets, hashes | Strings only |
| Persistence | Optional (RDB/AOF) | None |
| Replication | Built-in | Not native |
| Max Key Size | 512MB | 1MB |
| WordPress Support | Excellent (multiple plugins) | Good (fewer plugins) |
| Clustering | Redis Cluster | Client-side |
For WordPress, Redis is the stronger choice. Its richer data structure support, built-in persistence options, and mature plugin ecosystem make it the standard recommendation from most managed WordPress hosts.
Security Hardening for Redis
Redis is designed for trusted environments. On a web server, you must lock it down:
Never expose Redis to the public internet. The default port 6379 is one of the most scanned ports by automated bots. Disabling dangerous commands prevents accidental or malicious cache wipes. If you need these commands for maintenance, rename them to something obscure rather than disabling them entirely.
Performance Tuning Tips
After the basic setup, these optimizations squeeze extra performance from your Redis installation.
Use Unix Sockets Instead of TCP
If Redis and WordPress are on the same server, Unix sockets eliminate TCP overhead:
Then configure WordPress to use the socket:
Add your web server user to the Redis group:
Tune the Eviction Policy
The allkeys-lru policy works for most sites, but if you have frequently accessed data that should never be evicted, consider volatile-lru and set TTLs on less critical cache groups.
Enable Compression
The Redis Object Cache plugin supports compression to reduce memory usage:
Igbinary reduces serialized data size by up to 50% compared to PHP’s default serializer.
Managed Hosting: Redis Setup by Provider
Many managed WordPress hosts offer Redis as an add-on. Here is how to enable it on popular platforms:
Cloudways
- Go to Server Management > Settings > Packages
- Click Redis and set it to “Enabled”
- Navigate to Application Management > Settings
- Under Redis, toggle it on for your application
Kinsta
- Open the MyKinsta dashboard
- Go to Sites > Your Site > Add-ons
- Click Enable Redis (additional monthly cost applies)
WP Engine
- Redis is available on Growth plans and above
- Contact support to enable it on your environment
- The object-cache.php drop-in is automatically configured
Complete Setup Checklist
Use this checklist to verify your Redis installation is production-ready:
- Redis server installed and running (
redis-cli pingreturns PONG) - PHP Redis extension loaded (
php -m | grep redis) - wp-config.php configured with host, port, password, prefix
- object-cache.php drop-in installed in wp-content/
- Redis status shows Connected (
wp redis status) - Cache hit ratio above 85% after initial warmup
- Password authentication enabled
- Bound to localhost only
- Dangerous commands disabled or renamed
- Memory limit set appropriately
- Benchmarks recorded before and after
Redis object caching is one of the highest-impact performance optimizations you can make on a WordPress site. Once configured, it runs silently in the background, reducing database load and speeding up every page on your site. The setup takes 15-20 minutes and the performance gains last as long as your server runs.
For more WordPress performance techniques, check out our guide on fixing wp_options autoload bloat, OPcache configuration, and server-level caching strategies here on TweaksWP.
improve wordpress performance Object Cache Redis WordPress Performance wp-config.php
Last modified: February 24, 2026