Jim Westergren
About me, my projects, SEO, Web Development and Personal Development since 2005
"If we did all the things we are capable of, we would literally astound ourselves." - Thomas A. Edison

How to load WordPress in a few milliseconds using Redis

WordPress plus Redis = Love

Redis is an advanced key-value store. Like memcached on steroids. Everything is in the RAM and you can theoretically reach 100 000 GET per second with Redis.

My solution below will cache all the HTML output in Redis and display it without the need to load WordPress.

A big thanks to Jeedo Aquino who have rewritten and improved my original solution. Details here. This article updated on the October 25, 2012 with the new code.

If you don't already have your own VPS or server - do these steps first: Guide: WordPress with Maximum Performance and Speed.

Installing Redis

If you are using Debian then just:


apt-get install redis-server

Or else, just see the installation instructions.

Using Predis as a PHP client for Redis

You need a client in order to use PHP to communicate with Redis.

I recommend Predis. Upload predis.php to the WordPress root directory. See more about Predis on Github (if you use a newer version of Predis you need also to modify the script below).

Installing the PHP script for the Frontend Cache

Step 1:

Add the code below to a new file called index-with-redis.php and place it in the WordPress root directory.

Step 2:

Optional: modify the 3 variables at the top of the file.

Step 3:

If you are using Apache change all occurances of index.php to index-with-redis.php in the .htaccess.

If you are using the more preferred nginx then you need to rename index-with-redis.php to index.php. Unfortunately this also means that you have to replace this file each time you upgrade WordPress. You can also change nginx.conf to access index-with-redis.php instead of index.php but it creates some bugs and I would avoid that.

Step 4:

Deactivate all other caching plugins.

Instructions and info:

Benchmark for this blog:

I have been using this setup for this blog for quite some time now and all has been working well.

Some other advice

I am using the following setup for this blog: Nginx + PHP-FPM + APC + Cloudflare + Redis. Hosted on a nano VPS with 6sync for $15 per month. No caching plugins. It is maybe the fastest way to serve WordPress today. See here all the steps I did to setup this.

Make sure you also send HTML as gzip to the browser. You can do that in the .htaccess (Apache), nginx.conf (Nginx) or via CloudFlare.

See also my article: Why I recommend CloudFlare and why you should try it too

Please comment

I would love to hear from you!

25 Oct 2012

About the Author Jim Westergren Jim Westergren is a Swedish web entrepreneur currently living in Spain. He is happily married and has three lovely children. Some of his interests are web development, SEO and writing.
He is the Founder of DomainStats and N.nu. Read his .