Installing Redis on your WordPress Website
WordPress uses MySQL for all of its data storage, and with high traffic, eCommerce, and complicated websites, MySQL starts to become the bottleneck for page load times. Database performance is one of the key optimizations we often look at when trying to speed up your website.
Since Google is placing a higher priority on page load times for your SEO, it’s becoming more and more important to make sure your site loads quickly.
That’s where Redis comes in. Redis is an in-memory database, and because of that, it has very fast performance when compared to MySQL.
Redis can be used as a middleman – a cache – for your WordPress website, and greatly reduce the amount of time spend reading the database. By storing commonly accessed information, Redis bypasses MySQL and delivers your pages much, much faster. Considering that the average WordPress page hits the database around 60-80 times (a fresh, basic install is around 30), using a cache seems like a no-brainer.
Now, Redis isn’t available on every server. Luckily Eggplant’s hosting service has Redis installed and ready to go. To use Redis:
- Take some initial benchmarks for your page speed
- Download and install the Redis Object Cache plugin
- Open your wp_config.php file, and add the line:
Replacing yourdomain.com with, well, your domain!
- Navigate to Settings -> Redis and click Enable Object Cache
- Recheck your page load times
Note: Redis Object Cache seems to conflict with WP Super Cache, but WP Super Cache has it’s own Redis option – so consider setting it up through WP Super Cache (tutorial to come!)
Note 2: the WP_CACHE_KEY_SALT is a very important value, and must be unique for every site you install the Redis Object Cache on – including your development sites! I suggest using your domain name, as it’s likely to be unique. For a development site, I simply use .dev as the TLD, and change it when I publish the site. Failing to maintain a unique WP_CACHE_KEY_SALT can cause your site to go offline. If that happens update the value in your wp_config.php file, or in extreme cases FTP in and rename or remove the Redis Object Cache plugin, and remove the wp-content/object-cache.php file.