Table of contents

The title says it all, and those familiar with WP Rocket probably know this story (or problem), but I’ll go into a bit more detail.

We use a WP Rocket Multisite license and apply it to most of the projects we work on. It’s already become a habit, the product works well, it’s simple to set up, and in 90% of projects it works without issues.

One drawback of WP Rocket is that it doesn’t do Object Caching.

So below I’ll go through a few steps to set up Redis and connect it to WordPress, plus some special situations.

How to Install Redis

One option is to contact your hosting support and ask them to install Redis. This is the easiest option, especially if you’re not very technical or simply don’t want to complicate things.

The second option is to follow the official Redis instructions:

It’s quite simple; the commands below are sufficient for most cases.

Ubuntu/Debian:

sudo apt-get install lsb-release curl gpg
curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg
sudo chmod 644 /usr/share/keyrings/redis-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list
sudo apt-get update
sudo apt-get install redis

Then you need to make Redis start when the server boots:

sudo systemctl enable redis-server
sudo systemctl start redis-server

And that’s it – now you have Redis on your VPS.

Connecting WordPress to Redis

The simplest way is with the Redis Object Cache plugin.
Install the plugin and activate it.
If you have a single site on the VPS, you don’t need to do anything else.

It shows you if there’s a connection and if it’s set up correctly.

[image here]

Redis Settings for Multiple WordPress Instances

However, if you have multiple WordPress instances on the same VPS where Redis is installed, then you need to make a change.

The Redis Object Cache plugin automatically assigns Redis database 0 when installed. If you have multiple WordPress instances and have installed the plugin on all of them, each will be connected to database 0 in Redis, which will cause errors.

To prevent this, you need to assign different databases for each WordPress instance.

In wp-config.php, add the following line:

define('WP_REDIS_DATABASE', 1);

Where you define the Redis database number for that WordPress instance. You need to keep track of which one you used where to avoid confusion later. In WordPress, in the plugin settings, you can see the database used for that site.

IMPORTANT
A Redis instance, in default mode, has databases 0-15 available – that’s 16 databases in total. Theoretically, you couldn’t have more than 16 different sites connected to Redis for Object Caching without additional modifications.

If you want more, you need to modify redis.conf:

nano /etc/redis/redis.conf

Find the line:

And change it to:

Then restart the service:

sudo systemctl restart redis

Now you have 32 databases available for Redis. Here, potential problems related to the memory you have available on the VPS may also come into play.

WordPress Multisite and Redis

Redis Object Cache works perfectly with Multisite. It uses a single Redis database; you don’t need to use different databases for each site within Multisite.

At the moment, I use it in two WordPress Multisite instances – one with 2 sites, one with 20 – and everything works without problems.

Advanced Settings

If you want more control, there’s a whole list of settings that can be adjusted.

The only ones I’ve added to wp-config.php are:

define('WP_REDIS_MAXTTL', 86400);
define('WP_REDIS_TIMEOUT', 3600);

To ensure that after a period, the memory used in Redis is cleaned up.
This depends a lot on the type of site – whether the content is dynamic, whether it changes often, whether you have third-party plugins that might not clean up after themselves, and there’s also the issue of memory allocated elsewhere.
By default, you don’t need to change or modify these settings in most cases.

Do You Need Redis?

It depends.

If you’re using a dedicated WordPress hosting service, you probably don’t need Redis because there’s already an Object Caching service included in the package. My recommendation would be to use the one included by the hosting company. Because you don’t have to worry about it, it’s probably already running, and in the hosting control panel you have some options.

However, if you’re using a VPS that you manage yourself, then Redis is likely a good solution. Especially if you’re using a caching plugin that doesn’t do Object Caching, like WP Rocket.

Conclusion

For me, it fits perfectly since I have multiple VPSs where clients are hosted, and for all of them I use WP Rocket. The logical option was to add Redis to cover the Object Caching part and keep WP Rocket for the rest of the performance optimizations.

This isn’t the only configuration I use, but it’s currently the most popular one.