Our Blog
Solutions. Made Simple.

Speeding Up Magento With Redis

We recently developed an online shop in Magento and were looking at ways to improve the site’s responsiveness. Magento can be a lumbering beast at times, with it’s endless feature list and huge number of database tables, so performance tweaking is essential if you want to build a successful e-commerce platform.

Having worked on a number of Magento shops before we ran through the usual optimisation techniques (enabling caching, enabling compilation, using Apache’s GZIP compression to compress pages and setting up reasonable caching times for resources) but we were still hungry for more speed. Our research then lead us to Redis, an open source, in-memory, key-value store which can be used to replace the filesystem based cache built into Magento.

So, we knew we wanted to use Redis… What next?! Some more research threw up the key points which will be important to anyone wanting to implement Redis with Magento.

Firstly, Magento CE 1.8 and up comes with the required modules built in and is therefore much easier to get up and running. The modules do exist for versions 1.7 and below, so it’s still possible, but it does involve more work and it could simply be easier to upgrade Magento to the latest version ( at the time of writing). Forgive the shameless plug but if you do need help upgrading Magento we have experience all the way back to 1.3 so get in touch.

Secondly there are a number of prerequisites you’ll need to take care of before configuring Magento. Specifically you’ll need the following, latest versions are always preferable:

  • Redis server (naturally!)
  • PHP Redis extension

And that’s about it! The above can be installed on most Linux systems using yum, as follows:

yum install redis php-pecl-redis

And you should be left with a system that’s ready to go. First off we need to start the Redis server, make sure it comes back if the server is ever restarted and check it’s running:

/etc/init.d/redis start
chkconfig redis on
redis-cli ping

And reply of ‘PONG’ means everything is looking good. We also need to restart Apache and check the Redis support we just installed is loaded:

/etc/init.d/httpd restart
php -m | grep redis

You should see a single word response from the last command, ‘redis’, which confirms the module is ready to go. Next we need to modify the Magento local.xml file with details of our new Redis server and what we want to use it for. Open up app/etc/local.xml and add the following anywhere in the <config><global>…</global></config> block:




















All of these are basically defaults, with the exception of the <database>/<db> and <persistent> settings. These need to be set uniquely for the server otherwise you will most likely get weirdness of all kinds which is never a good thing. At this point you’ll also want to make sure the <session_save> option already in your local.xml is set to ‘db’ as this is overwritten at runtime by the Redis module.

Next step? There isn’t one! Magento will now use the Redis server to store user sessions and page cache, which should see your page response times cut in half. We had some basic benchmarks and we saw a 25%-50% reduction in page response times across the site, even including pages which wouldn’t normally receive a boost from caching (such as the checkout). Maybe this reduced the server load sufficiently that it appeared to speed up these pages despite not having a direct effect? We haven’t looked into it enough yet to know for sure but we do know the site is now running great and using less resources than we’ve ever seen Magento use before.