Redis is an open source, in-memory data structure store, used as a database, cache and message broker that can be used as a drop-in caching back-end for your Drupal or WordPress website. Its similar like Memcache. If you a question in mind like which Caching system is best Memcache or Redis, I would say its hard to tell, Both caching systems have their own Advantages. Its up to you which one you would like to use and what kind of configuration setup better suits your environment. Normally Webmasters use Redis as caching module and there by improve the site loading time of websites. There is no in house option like cPanel Redis plugin at this moment. We need to install the Redis caching server manually on a cPanel based server. Today we discuss further on it.
Before proceed with the installation method we follow, I would also like to mention one point as, I have noticed, there is a third party plugin exists for Redis cache developed by a company named unixy.net. If you liked it you can also purchase it from their below url.
How does the Redis caching works
Most website frameworks like WordPress use the database to cache internal application “objects” which can be expensive to generate (menu trees, filter results, etc.), and to keep cached page content. Since the database also handles many queries for normal page requests, it is the most common bottleneck causing increase load-times. Redis provides an alternative caching back-end, taking that work off the database, which is vital for scaling to a larger number of logged-in users. This is achieved by storing the query results as memory blocks.
Advantage of Redis
Caching with Redis will not have the need to manually flush the cache when new content is published. Additionally if a page or blog post edited, the Redis cache for that content will be invalidated and will the updated content after the next refresh of page.
The Redis daemon and Redis PHP Extension is the one we need to install. To complete the installation steps below you will need root access to your server. So if you don’t have a root access to the server, get it before proceed further. Below is the system environment I used for testing. Which doesn’t mean that you need exact same environment. You can follow the idea behind it if you have old Centos 6 version or you have Latest Centos7 and cPanel/WHM versions.
To make sure Redis is working, run command “redis-cli ping” from command line. If you get result “PONG”, that shows Redis is working.
At this point the Redis caching server is up and running on our server. Normally the configuration file of Redis located at /etc/redis.conf. We can add the following 2 lines at the end of the file for setting a memory limit for Redis install. Set this value as per your desire and system according to your available system memory. In this example I am setting the value as 512Mb
Install PHP Redis extension
Use following commands for installation of php Redis extension.
Lets see how we can configure or integrate our WordPress install with Redis server.
- Install plugin named Redis Object Cache plugin
- Go the Wp-Admin area of word press and click the “Object Cache” button.
- Edit our wp-config.php and add below two lines at the end of the file Authentication Unique Keys and Salts section, Note that string can be anything you want, as long as it’s unique. it will be better if you set your domain name as string.
Restart Apache and Redis services in the server using below commands.
In order to test whether the WordPress install is cached by WordPress, issue “redis-cli monitor” command over SSH and click any link in the wp-admin area. The result should be like below. It means we can see log entries appear and that conclude WordPress is communicating with Redis.