How does the caching work?
The first time a WordPress page is loaded, a database query is performed on the server.
Redis remembers, or caches, this query. So, when another user loads the WordPress page, the results are provided from Redis and from memory without needing to query the database.
The Redis implementation used in this guide works as a persistent object cache for WordPress (no expiration).
An object cache works by caching the SQL queries in memory which are needed to load a WordPress page. When a page loads, the resulting SQL query results are provided from memory by Redis, so the query does not have to hit the database. The result is much faster page load times, and less server impact on database resources.
If a query is not available in Redis, the database provides the result and Redis adds the result to its cache. If a value is updated in the database (for example, a new post or page is created in WordPress) the Redis value for that query is invalidated to prevent bad cached data from being presented.
Redis and LiteSpeed:
If you are using the LiteSpeed cache plugin, then this is the recommended method of implementing Redis.
Login to the Admin Dashboard and go to: LiteSpeed Cache >> Settings >> Cache >> Object Cache >> and fill in your Redis details, as per your cPanel:
Redis and W3 Total Cache:
That's another way of integrating Redis into your WordPress, suitable if you are not using the LiteSpeed cache plugin.
Click on General Settings and enable Database Cache and Object Cache, choosing Redis as Cache Method:
Under Performance, you'll see separate menus for Database Cache and Object Cache. That's where you'll need to configure the Redis hostname and database ID.
Select Database Cache then enter your Redis hostname / Your Redis socket address as it is appearing in your cPanel.
Use persistent connection should be enabled and Redis Database ID should be unique number dedicated for this cacheing type.
note: If you use WooCommerce, then you must add _wc_session_ to the "Ignored query stems" section.
Next stop is the Object Cache, where you'll need to enter the same Redis hostname / Your Redis socket address and unique Redis Database ID.
Redis should now be fully integrated into WordPress.