Redis Object Cache for WordPress: Setup Guide
In this article
Setting up a Redis object cache in WordPress reduces the load on your MySQL database by storing frequently accessed data in memory. Instead of querying the database every time a page loads, WordPress retrieves the data from Redis, which significantly decreases page load times and improves server responsiveness, especially for high-traffic sites or complex e-commerce stores.
What You'll Need
- A WordPress website with administrative access.
- A server with Redis installed (most managed WordPress hosts provide this, or you can install it via SSH on a VPS).
- The PHP Redis extension installed and enabled on your server.
- FTP/SFTP access or a File Manager to edit the
wp-config.phpfile.
Step-by-Step
-
Verify Redis Installation: Before configuring WordPress, ensure Redis is running on your server. If you have SSH access, run the command
redis-cli ping. If the server is working, it will respond withPONG. If you are on managed hosting, check your hosting dashboard under "Caching" or "Performance" to toggle Redis on. -
Install the PHP Redis Extension: WordPress requires a bridge to communicate with the Redis server. Ensure the
php-redisextension is installed. On Ubuntu/Debian servers, this is typically done viasudo apt-get install php-redisfollowed by a restart of your web server (e.g.,sudo systemctl restart apache2orsudo systemctl restart php-fpm). - Install a Redis Object Cache Plugin: Navigate to your WordPress Dashboard, go to Plugins > Add New, and search for "Redis Object Cache". Install and activate the plugin. This plugin acts as the interface between WordPress and the Redis server.
-
Configure wp-config.php: While the plugin handles most settings, you may need to define the Redis host and port in your
wp-config.phpfile for optimal stability. Open the file via SFTP and add the following lines before the/* That's all, stop editing! Happy publishing. */comment:define( 'WP_REDIS_HOST', '127.0.0.1' ); define( 'WP_REDIS_PORT', 6379 );
If your Redis server is on a separate instance or uses a password, adddefine( 'WP_REDIS_PASSWORD', 'your-password-here' );. - Enable the Cache: Go to Settings > Redis in your WordPress dashboard. Click the "Enable Object Cache" button. The status should change to "Connected" if the configuration is correct.
- Flush the Cache: To ensure all current data is correctly indexed in the new system, click "Flush Cache" within the plugin settings. This clears out old stale data and starts the caching process fresh.
Common Mistakes
- Installing the plugin without the server software: The plugin is only a client. If the Redis server is not installed and running on the actual machine/server, the plugin will show a connection error.
- Ignoring the PHP extension: Many users install Redis on the server but forget the PHP extension. Without
php-redis, WordPress cannot "talk" to the Redis service. - Using Redis on very low-RAM servers: Redis stores data in RAM. If your server only has 512MB or 1GB of RAM and is already struggling, Redis can lead to "Out of Memory" (OOM) errors, causing the database or web server to crash.
- Duplicate Caching: Using multiple object cache plugins simultaneously can cause conflicts and site instability. Stick to one.
Tips
- Set a Memory Limit: To prevent Redis from consuming all your server's RAM, set a
maxmemorylimit in yourredis.conffile (e.g.,maxmemory 256mb) and set the policy toallkeys-lruto automatically evict the oldest data. - Use a Unique Prefix: If you host multiple WordPress sites on one Redis server, use a unique prefix in
wp-config.phpto prevent one site from clearing another's cache:define( 'WP_CACHE_KEY_SALT', 'site1_' );. - Monitor Performance: Use the
redis-cli monitorcommand via SSH to see real-time requests hitting your cache and verify that the system is working as intended.
Troubleshooting
If you encounter a "Connection Refused" or "Unable to connect to Redis" error, check the following:
- Service Status: Run
sudo systemctl status redisto ensure the service is active. If it is stopped, start it withsudo systemctl start redis. - Port Binding: Ensure Redis is listening on the correct port (default 6379). Check your
redis.confto see if it is bound to127.0.0.1or another IP address. - Firewall Rules: If Redis is on a separate server, ensure the firewall allows traffic on port 6379 between the web server and the Redis server.
- Plugin Conflict: If the site becomes sluggish or displays errors, deactivate the Redis plugin and check if the issue persists. If it disappears, review your
wp-config.phpfor typos.
Frequently Asked Questions
Is Redis better than Memcached?
Redis is generally considered more powerful because it supports more data types and offers persistence (saving data to disk), whereas Memcached is a simpler, pure-memory key-value store.
Will Redis slow down my admin dashboard?
No, it typically speeds up the admin dashboard by caching complex database queries used by the WordPress backend.
Do I still need a page caching plugin?
Yes. Redis is an object cache (caching database queries), while plugins like WP Rocket or W3 Total Cache provide page caching (caching the final HTML). They work together for maximum performance.
Does Redis affect SEO?
Indirectly, yes. By reducing server response time (TTFB), it improves the user experience and page speed, which are factors in search engine rankings.
Can I use Redis on shared hosting?
Only if your hosting provider explicitly supports it and provides the Redis server and PHP extension. Most basic shared plans do not allow this.