User Agents

Web browsers and everyday web tech, explained

Redis Object Cache for WordPress: Setup Guide

· 4 min read · Cookies and Cache

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

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.php file.

Step-by-Step

  1. 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 with PONG. If you are on managed hosting, check your hosting dashboard under "Caching" or "Performance" to toggle Redis on.
  2. Install the PHP Redis Extension: WordPress requires a bridge to communicate with the Redis server. Ensure the php-redis extension is installed. On Ubuntu/Debian servers, this is typically done via sudo apt-get install php-redis followed by a restart of your web server (e.g., sudo systemctl restart apache2 or sudo systemctl restart php-fpm).
  3. 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.
  4. Configure wp-config.php: While the plugin handles most settings, you may need to define the Redis host and port in your wp-config.php file 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, add define( 'WP_REDIS_PASSWORD', 'your-password-here' );.
  5. 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.
  6. 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 maxmemory limit in your redis.conf file (e.g., maxmemory 256mb) and set the policy to allkeys-lru to 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.php to prevent one site from clearing another's cache: define( 'WP_CACHE_KEY_SALT', 'site1_' );.
  • Monitor Performance: Use the redis-cli monitor command 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 redis to ensure the service is active. If it is stopped, start it with sudo systemctl start redis.
  • Port Binding: Ensure Redis is listening on the correct port (default 6379). Check your redis.conf to see if it is bound to 127.0.0.1 or 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.php for 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.