Live Blog

Redis Cache Clearing Causes Redis Plugin Error

Introduction

You might have had reports or experienced a time when a site showed a Redis Plugin error similar to the one below.

Error establishing a Redis connection

read error on connection to /var/run/redis/redis-server.sock

WordPress is unable to establish a connection to Redis. This means that the connection information in your wp-config.php file are incorrect, or that the Redis server is not reachable.

Is the correct Redis host and port set?
Is the Redis server running?
If you need help, please read the installation instructions.

To disable Redis, delete the object-cache.php file in the /wp-content/ directory.

Now this is a generic error, so if you came here from google, then this issue might not apply to your situation.

Using WP_REDIS_SELECTIVE_FLUSH to Clear Redis

The issue is caused when using WP_REDIS_SELECTIVE_FLUSH when trying to clear Redis. You might see the following in your log.

Lua slow script detected: still in execution after 5029 milliseconds. 

I brought this to the developer of the Redis Cache plugin

Purging Cache Results in Error · rhubarbgroup · Discussion #18 · GitHub
Purging Cache Results in Error
github.com

Here’s what Till Kruss had to say.

You are using WP_REDIS_SELECTIVE_FLUSH which will take longer than 5s if your database is too large. Turn it off and use dedicated databases for each site.

We don’t officially support WP_REDIS_SELECTIVE_FLUSH anymore and recommend using WP_REDIS_DATABASE instead, it’s instantaneous.

No, WP_REDIS_SELECTIVE_FLUSH is marked as deprecated because it will always be flawed.

I’ve told the GridPane guys that they need to use separate WP_REDIS_DATABASE for each site, Redis can easily have 1000+ database indices without any performance loss.

Since the site in question was on a GridPane server, GridPane wasn’t using separate databases at the time (Ubuntu 18) for each site and therefore had to use WP_REDIS_SELECTIVE_FLUSH of which uses a single Redis database and a key to clear data of a single site and not all sites in the database.

This is not an issue if you use WP_REDIS_DATABASE for each site, (GridPane released this in Ubuntu 22) which in-turn will flush the whole database versus just items based on a key.

Conclusion

Upgrade to Ubuntu 22 on GridPane, or move to using a Redis database for each site.

0 Shares: