increase wordpress site speed using redis cache

Hi Techrunnr readers, this document deals with how to increase wordpress site speed using redis cache.


Redis, RE-dis is an open-source in-memory data structure project implementing a distributed, in-memory key-value database with optional durability. Redis supports different kinds of abstract data structures, such as strings, lists, maps, sets, sorted sets, hyperloglogs, bitmaps, and spatial indexes.

How Does Redis cache work?
Redis cache will store all the request which is going to database and later the requests are served from Redis cache not directly from the server.
For example, if a user visits and searches for some keyword in the blog, the first time all the queries will reach the database server and provides the result to the user. These all query information will get stored in Redis cache and memory. And later on, if a request comes for the same query, the results are server from the Redis cache not from the database.
Using this way the Redis caches minimizes the querying with database and improves the speed.
Redis can increase the performance of site load time from 655ms to 376ms.

If you go any wrong with the caching system, you can flush the Redis cache contents using flushall command in redis-cli.

Here we are going to setup Redis cache in running WordPress server in order to increase the speed of the site.

Prerequisites

* WordPress running site.

1. Installation of Redis

apt-get install redis-server // In ubuntu

yum install redis-server //In centos

2. Configuration

Add the following lines in Redis configuration

maxmemory 256mb
maxmemory-policy allkeys-lru

Download the redis cache script

wget https://www.techrunnr.com/object-cache.php

cp object-cache.php /var/www/html/wp-contents/

Add the following lines in wp-config.php

vi /var/www/html/wp-config.php

define('WP_CACHE_KEY_SALT', 'domain.com');
define('WP_CACHE', true);

3. Restart Apache2 and Redis-server

/etc/init.d/apache2 restart
/etc/init.d/redis-server restart

4. Test Redis cache

Execute the following command to see redis is working or not

redis-cli monitor

Expected Output

1537416916.166500 [0 127.0.0.1:44660] "EXISTS" "wp_:options:alloptions"
1537416916.166650 [0 127.0.0.1:44660] "GET" "wp_:options:alloptions"
1537416916.167115 [0 127.0.0.1:44660] "EXISTS" "wp_:options:notoptions"
1537416916.167260 [0 127.0.0.1:44660] "GET" "wp_:options:notoptions"
1537416916.167414 [0 127.0.0.1:44660] "EXISTS" "wp_:options:alloptions"
1537416916.167549 [0 127.0.0.1:44660] "GET" "wp_:options:alloptions"

If you are not getting the expected output, just browse your website.

Now you can do see the website performance has been increased as compared before.

It’s always better to do a benchmark before and after Redisis-server installation.

© 2018, Techrunnr. All rights reserved.

#1
#2
#3
Questions Answered
Articles Written
Overall Points

Prabhin Prabharkaran

He is Technical professional. He is a person who loves to share tricks and tips on the Internet. He Posts what he does!!

Leave a Reply

Please wait...

Subscribe to our newsletter

Want to be notified when our article is published? Enter your email address and name below to be the first to know.