Posted by

Magento – use Redis as cache backend

We will configure Magento to use Redis as main cache backend.

1. Install Redis. (2.4 is required because it supports operating on multiple keys for many operations)
2. Install phpredis. For 2.4 support you must use the “variadic” branch: git checkout -t -b variadic origin/variadic, phpredis is optional, but it is much faster than Redisent.
3. Install this module git://github.com/colinmollenhour/Zend_Cache_Backend_Redis.git
4. Edit app/etc/local.xml to configure

Based on this article we have turned off cache disk :

<cache>
    <backend>Zend_Cache_Backend_Redis</backend>
    <slow_backend>database</slow_backend>
    <slow_backend_store_data>0</slow_backend_store_data>
    <auto_refresh_fast_cache>0</auto_refresh_fast_cache>
    <backend_options>
        <server>127.0.0.1</server>
        <port>6379</port>
        <database>database</database>
        <use_redisent>0</use_redisent>  <!-- 0 for phpredis, 1 for redisent -->
        <automatic_cleaning_factor>20000</automatic_cleaning_factor> <!-- optional, 20000 is the default, 0 disables auto clean -->
    </backend_options>
</cache>

To check if everything works fine you can use redis-cli :

flexishore@virtualbox:~$ redis-cli
redis 120.0.01:6379> select database
OK
redis 127.0.0.1:6379> keys *
   1) "zc:d:97a_REC_0000000510"
   2) "zc:d:97a_REC_0000000511"
   3) "zc:d:97a_REC_0000001240"
   4) "zc:d:97a_REC_0000000512"
   .......

As you can see, there are a lot of cache indexes in Redis database.

Source code : link
Benchmark class : benchmark.php

3 thoughts on “Magento – use Redis as cache backend

  1. Hi Rafal,

    Its now some month since you tested redit as a backend for magento. How well did your tests go?

    Can you eventually write a blogpost about redit and magento.

    Best regards
    Martin

  2. Pingback: Using Redis as Magento’s cache backend | Drew Gillson

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">