Using Redis to speed up WP

Before I start, yes I know that this isn’t a new topic, but many Developer’s still aren’t taking advantage of the caching techniques available.

So, you have an awesome WordPress site which is gathering some momentum and the content base is ever growing. You notice the site starting to slow down and struggle with the increasing load.

If this is the case, then the likelihood is that your database queries are the bottleneck. (There may be work to do on frontend assets, but I’ll leave that for another blog post)

Now, in comes Redis. In short it basically creates a memory store for your data, this relieves MySql from being hit on page load. Tie that in with a nicely optimised Nginx configuration file and you will be able to handle massive load on scarce resource.

First of all, you need to install Redis on your server. A great guide for that is here: https://www.digitalocean.com/community/tutorials/how-to-install-and-use-redis

Now, that you have Redis installed and configured on your server, you need to add a couple of files into your Wordpress root:

First of all you need to add Predis, this is the class to interface PHP with Redis

Now, we need to add an index file which hits Redis if a memory clusture is available. If not it makes one available so that only the minimum amount of SQL queries are made

Finally, you will want to add a couple of location blocks to your Nginx conf file and also make it look at wp-index-redis.php before index.php

And that’s it, Wordpress will now load through Redis. Sit back and watch your site speed up instantly.