Redis Object Cache is one of the most effective techniques for speeding up a WordPress website, particularly for sites that make frequent MySQL database calls — such as e-commerce stores, membership sites, or content-heavy publications with many categories and widgets. Redis works by storing the results of database queries and PHP objects in RAM, so WordPress does not have to repeat the same queries on every page request. This guide walks you through installing and configuring Redis Object Cache from scratch, all the way to validating that it is working correctly and tuning it for maximum performance.
How Redis Object Cache Works with WordPress
WordPress ships with a built-in Object Cache API, but by default it only stores data for the lifetime of a single PHP request. This means the cache is thrown away when the request ends, and the very next visitor triggers exactly the same database queries all over again. On a site with heavy plugins — page builders, WooCommerce, SEO plugins, and custom widgets — a single page load can trigger more than 100 MySQL queries.
Redis acts as a persistent external object store. Because it runs as a separate process and stores data in RAM, the cache survives across PHP requests. When WordPress needs a piece of data it has fetched before, it retrieves it from Redis in microseconds instead of waiting for MySQL to execute a query, read from disk, and return the result.
- 60–90% reduction in DB queries on sites with many repeated queries
- Lower TTFB (Time to First Byte) — measurable improvement on plugin-heavy pages
- Better handling of traffic spikes because MySQL receives far fewer concurrent queries
- Works alongside Page Cache — Redis handles the PHP/DB layer; Page Cache handles the HTTP layer
System Requirements Before You Begin
You need three components in place before WordPress can use Redis as its object cache backend:
| Component | Minimum Version | Notes |
|---|---|---|
| Redis Server | Redis 4.0+ (6.x recommended) | Requires VPS or dedicated server with root access |
| PHP Extension | phpredis or predis | phpredis (C extension) is faster; predis is a pure-PHP fallback |
| WordPress Plugin | Redis Object Cache plugin | Available free on WordPress.org (by Till Krüss) |
| Server RAM | 1 GB total minimum | Allocate 64–256 MB to Redis depending on traffic |
If you are on shared hosting, check with your provider first — some managed hosting platforms expose a Redis endpoint without requiring server-level configuration. On a VPS, you have full root access and can install Redis exactly as described in this guide.
Step 1 — Install Redis Server on Ubuntu/Debian
Connect to your server via SSH and run the following commands:
sudo apt update sudo apt install redis-server -y
After installation, open the main configuration file and make several important changes:
sudo nano /etc/redis/redis.conf
Find and update the following settings:
# Bind only to localhost for security bind 127.0.0.1 ::1 # Tell Redis it is managed by systemd supervised systemd # Set a memory cap (adjust based on your available RAM) maxmemory 128mb # Eviction policy when the cache is full maxmemory-policy allkeys-lru # Optional but recommended: use a Unix socket for lower latency unixsocket /var/run/redis/redis-server.sock unixsocketperm 770
Save the file, then restart and enable Redis so it starts on boot:
sudo systemctl restart redis-server sudo systemctl enable redis-server # Verify Redis is running sudo systemctl status redis-server # Quick connectivity test redis-cli ping # Expected output: PONG
Step 2 — Install the PHP Redis Extension
WordPress needs a PHP extension to communicate with the Redis server. Check whether phpredis is already loaded:
php -m | grep redis
If nothing is returned, install the extension for your PHP version:
# For PHP 8.3 (change the version number to match your setup) sudo apt install php8.3-redis -y # Restart PHP-FPM to load the extension sudo systemctl restart php8.3-fpm # Confirm the extension is now loaded php -m | grep redis # Should output: redis
Pro tip: If your server uses cPanel or DirectAdmin, there may be a point-and-click interface to enable the Redis PHP extension under Software > PHP Extensions or MultiPHP INI Editor. Check the control panel first — it may save you several command-line steps.
Step 3 — Install and Configure the WordPress Plugin
In the WordPress admin, go to Plugins > Add New and search for "Redis Object Cache" by Till Krüss. Install and activate it.
Next, open your site's wp-config.php file and add the following constants before the line that reads /* That's all, stop editing! */:
// Redis Object Cache configuration define( 'WP_REDIS_HOST', '127.0.0.1' ); define( 'WP_REDIS_PORT', 6379 ); // If you enabled the Unix socket above, use this instead of HOST/PORT // define( 'WP_REDIS_PATH', '/var/run/redis/redis-server.sock' ); // Redis database index (0–15). Use different indexes if multiple WordPress // sites share the same Redis instance define( 'WP_REDIS_DATABASE', 0 ); // Connection timeouts in seconds define( 'WP_REDIS_TIMEOUT', 1 ); define( 'WP_REDIS_READ_TIMEOUT', 1 ); // Prefix to namespace cache keys — prevents collisions with other apps define( 'WP_REDIS_PREFIX', 'mywp_' ); // Maximum cache TTL in seconds (0 = no expiry, relies on LRU eviction) define( 'WP_REDIS_MAXTTL', 86400 ); // 24 hours
Save the file, then go to Settings > Redis in the WordPress admin and click Enable Object Cache. The plugin copies a drop-in file to wp-content/object-cache.php, which WordPress automatically uses as the persistent cache backend from this point on.
Step 4 — Verify the Cache Is Working
After enabling, the Settings > Redis screen should show:
- Status: Connected — the plugin reached Redis successfully
- Cache Hits / Misses — a healthy site typically reaches 80%+ hit rate after a warm-up period
- Used Memory — how much Redis RAM is currently occupied by WordPress data
You can also verify directly from the command line:
# View overall Redis statistics redis-cli info stats # Check memory usage redis-cli info memory # Count cached keys for your WordPress database redis-cli -n 0 dbsize # Watch live commands in real time (press Ctrl+C to stop) redis-cli monitor
For deeper per-request analysis, install the Query Monitor plugin. It shows each Object Cache hit and miss and identifies which plugins are making the most database calls.
Advanced Tuning for Maximum Performance
Once basic caching is running, these additional configuration changes push performance even further:
Switch from TCP to Unix Socket
A Unix socket bypasses the TCP/IP stack entirely and communicates directly via the file system, reducing connection latency for local processes. First, add the web server user to the redis group:
sudo usermod -aG redis www-data # Confirm the socket file exists ls -la /var/run/redis/redis-server.sock
Then update wp-config.php to use the socket path instead of host and port:
// Comment out the TCP settings // define( 'WP_REDIS_HOST', '127.0.0.1' ); // define( 'WP_REDIS_PORT', 6379 ); // Use the Unix socket define( 'WP_REDIS_PATH', '/var/run/redis/redis-server.sock' );
Set a Redis Password
Even though Redis is bound to localhost, adding a password provides defence-in-depth against privilege escalation attacks:
# In /etc/redis/redis.conf requirepass your-strong-password-here
# In wp-config.php define( 'WP_REDIS_PASSWORD', 'your-strong-password-here' );
Choose the Right Eviction Policy
The allkeys-lru policy is the best choice for WordPress object caching. When Redis reaches its memory limit, it silently removes the least-recently-used keys instead of returning errors. This means WordPress continues to work normally even when the cache is full — it just re-fetches uncached data from the database and re-populates the cache naturally.
# Apply in real time without a restart redis-cli config set maxmemory-policy allkeys-lru # Check the current setting redis-cli config get maxmemory-policy
Monitoring Redis Health Over Time
Ongoing monitoring helps you confirm that Redis is delivering value and catch problems early. The most important metric is the cache hit rate:
# Hit rate = hits / (hits + misses) × 100 redis-cli info stats | grep -E "keyspace_hits|keyspace_misses" # Sample healthy output: # keyspace_hits:185200 # keyspace_misses:9100 # Hit Rate: 185200 / (185200 + 9100) = 95.3%
A hit rate below 50% typically means maxmemory is too low, causing excessive eviction. Doubling the memory allocation usually resolves this. Also watch for a rising mem_fragmentation_ratio — if it exceeds 2.0, a Redis restart compacts memory and recovers performance:
redis-cli info memory | grep -E "used_memory_human|maxmemory_human|mem_fragmentation_ratio"
Common Problems and How to Fix Them
The following issues appear most often during setup and production use:
- Status: Not Connected — verify Redis is running with
systemctl status redis-server, check thatbindin redis.conf matches theWP_REDIS_HOSTin wp-config.php, and confirm no firewall rule is blocking port 6379 - object-cache.php was not created — check that
wp-content/is writable by the web server (755 ownership), or manually upload the drop-in file provided by the plugin - Low cache hit rate — increase
maxmemory, or use Query Monitor to find plugins making uncacheable direct DB calls - Site becomes slower after enabling Redis — reduce
WP_REDIS_TIMEOUTto 0.5 seconds. A high timeout means WordPress waits too long for a Redis response that never comes, adding latency on every request - Stale content visible to visitors — check
WP_REDIS_MAXTTLis not excessively high; also verify the plugin version is current, as older versions had cache invalidation bugs
Frequently Asked Questions (FAQ)
What is the difference between Redis Object Cache and Page Cache?
Page Cache (such as WP Super Cache or LiteSpeed Cache) stores fully-rendered HTML pages on disk so they can be served without running PHP at all. Redis Object Cache operates at the PHP/MySQL layer, storing the results of database queries and PHP objects in RAM so PHP does not have to repeat the same DB queries on every request. Both can be used together and complement each other — Page Cache reduces PHP overhead while Object Cache reduces database overhead.
Can Redis be used on shared hosting?
It depends on the hosting provider. Some managed hosting platforms offer Redis as a configurable option, but most shared hosting plans do not provide a dedicated Redis server. If Redis is unavailable, Memcached can serve as a partial alternative. The most reliable solution is a VPS where you have root access to install and configure Redis yourself.
Do I need to flush the cache every time I update content in WordPress?
The Redis Object Cache plugin automatically invalidates the relevant cache keys when you save a post, page, or update any WordPress option. You do not normally need to flush the cache manually. However, if you notice stale data being displayed, you can flush the cache from Settings > Redis in the WordPress admin, or run wp cache flush via WP-CLI.
How much RAM does Redis use and can it slow down my server?
Redis uses RAM up to the maxmemory value set in redis.conf. For a typical WordPress site, 64MB to 256MB is usually sufficient. Because Redis operates entirely in memory with no disk I/O, it adds very little CPU overhead and will speed up your server rather than slow it down. The only scenario where performance degrades is when maxmemory is set too low, causing frequent key eviction that reduces cache effectiveness.
WordPress-Optimized Hosting
AsiaGB Hosting supports PHP 8.3, MySQL, LiteSpeed Cache, and WordPress Toolkit — starting from just 500 THB/year.
View Hosting Plans