Procédure
What is Redis?
Redis is a very high-performance key-value storage service. Quite similar to Memcached, Redis has the advantage of being persistent: the data is not volatile.
Given the fairly simplistic nature of its data structure, and the fact that all the data is preloaded into memory when Redis starts up, searching and retrieving information from a Redis database using its unique key is much faster and less resource-intensive than retrieving the same information from a traditional database such as PostgreSQL or MySQL.
You can find out more about Redis on their official website.
Why and when should I use Redis as an object cache for WordPress?
The Redis object caching system is not to be confused with page caching systems such as Fastest Cache, LiteSpeed or WP-Rocket. Page caching systems cache an entire page that has already been built, whereas an object caching system allows you to cache certain elements of the site, such as an article, a comment, a product, etc.
An object cache system simply makes less of a demand on the MySQL database when building a page, while reducing response time, whereas a page cache system keeps a page completely built for later use. As a result, a Redis object cache system will not be beneficial for predominantly static sites such as blogs and storefront sites.
Only websites that are highly dynamic (their page content cannot be cached for long enough) are good candidates for object caching. This is particularly the case for certain ecommerce sites, sites with members' areas, discussion forums and certain blogs where the comment section is particularly active.
If your website has static content, you will be better off optimising page caching with Fastest Cache or LiteSpeed.
How do I activate Redis on cPanel?
The Redis service is available for all cPanel accounts on the default port (TCP 6379). For a PHP script to be able to communicate with a Redis server, it will need to be supplied with a suitable library. The most popular libraries include :
- PhpRedis (written in C language, supplied as a PHP extension): to be activated via the cPanel interface
- Predis (written in PHP, supplied as a PHP dependency that can be installed using the composer utility): to be installed using the composer command or, in most cases, already supplied inside your PHP script (usually in the "vendor" folder).
Depending on the PHP script you're using, you'll be able to use one, the other or both. The WordPress plugin we're going to recommend is compatible with both libraries.
Activating PhpRedis on cPanel
To activate PhpRedis, which is the PHP Redis extension, log in to your cPanel interface and click on"Select a PHP version" in the"Software" section.

Tick the"Redis" extension to activate it.

How do I use Redis as a persistent object cache on WordPress?
To use Redis as an object cache on WordPress, you will need to install the Redis Object Cache plugin. From your WordPress dashboard, go to"Extensions" then"Add".

Search for the"Redis Object Cache" plugin and click on"Install now".

Once the installation is complete, activate the plugin by clicking on the"Activate" button.

From your cPanel file manager, edit your wp-config.php file and add the following lines:
define( 'WP_REDIS_CLIENT', 'phpredis' ); define( 'WP_REDIS_SELECTIVE_FLUSH', true); define( 'WP_REDIS_PREFIX', 'monsite.com' );

- The value of WP_REDIS_CLIENT allows you to choose the library used by the WordPress plugin to access Redis: phpredis or predis.
- The value of WP_REDIS_SELECTIVE_FLUSH allows you to delete only the data with the prefix defined on WP_REDIS_PREFIX during a total cleanup of the Redis cache.
- The value of WP_REDIS_PREFIX allows you to specify a key prefix for the data on your site (so that it does not conflict with other sites). It is important to specify a unique prefix for each site.
Once you've added these settings and saved the file, return to your WordPress dashboard. In Settings then Redis, activate the Redis object cache system:

Cache calibration options can be added to wp-config.php for more specific needs. For more information, please consult the plugin's official documentation.
How can I use Redis on WordPress with W3 Total Cache?
You can also use the WordPress plugin W3 Total Cache to cache the results of database queries. Note that this method is different from object caching. It is only recommended if a heavily used plugin does not use the WordPress object system (such as custom post types) to store and retrieve data.
1. Log into your WordPress Dashboard and go to"Extensions/Add".

2. Search for the"W3 Total Cache" plugin and click on"Install now".

3. Activate the plugin by clicking on the button.

4. Click on"Settings" below the plugin to access its configuration.

5. Go to the"Database caching" section, tick the"Database checkbox" box and choose"Redis" from the drop-down window. Finally, click on"Save settings and purge cache" to save your request.

Conclusion
You are now able toactivate and configure the Redis Object Cache plugin on your Wordpress site with your cPanel web hosting. Note that all Redis data is accessible to all users of the same cPanel server. As a result, it is imperative never to store sensitive information on Redis.
Don't hesitate to share your comments and questions.