Magento supports many backend cache with the help of the Zend framework. Memcache and APC are commonly used. However, Redis is rapidly becoming a popular and powerful cache system for Magento and other web applications.
Redis is an open source, BSD licensed, advanced key-value store that can optionally be used in Magento for back end and session storage. It can be used to cache the database resulting in exploitation of less database resources, and provides a tunable persistent cache. It is a good alternative to memcacheD.
When first time page is loaded, a database is queried on the server. Redis caches the query. Next time other user loads the page the results are provided from the redis without quering the actual database. It implements a persistent object cache (no expiration). An object cache works by caching the SQL queries in memory which are needed to load the web page. When the data of main database server is updated,then corresponding key in the redis is invalidated. So the it provides the updated data instead of caching the data. If a query is not available in redis, the database provides the result and it adds the result to its cache.
So, let’s begin with its installing and configure it for Magento.
Update and install redis-server.
|
1 2 3 4 5 |
sudo su apt-get update apt-get install redis-server |
Configure Magento,
|
1 |
nano //app/etc/modules/Cm_RedisSession.xml |
To enable the module, edit
|
1 2 3 4 5 6 7 8 9 10 |
false community |
To
|
1 2 3 4 5 6 7 8 9 10 |
true community |
Then, edit the ‘local.xml’ file located in magento directory.
|
1 |
nano /magento-root-dirrectory/app/etc/local.xml |
Change
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
<![CDATA[Tue, 04 Oct 2016 09:53:37 +0000]]> <![CDATA[e972f3c4e8436052de805bdf1f40de0f]]> false <![CDATA[]]> <![CDATA[localhost]]> <![CDATA[magento]]> <![CDATA[magento]]> <![CDATA[magento]]> <![CDATA[SET NAMES utf8]]> <![CDATA[mysql4]]> <![CDATA[pdo_mysql]]> <![CDATA[]]> 1 <![CDATA[files]]> <![CDATA[admin]]> |
To
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
<![CDATA[Tue, 04 Oct 2016 09:53:37 +0000]]> <![CDATA[e972f3c4e8436052de805bdf1f40de0f]]> false <![CDATA[]]> <![CDATA[localhost]]> <![CDATA[magento]]> <![CDATA[magento]]> <![CDATA[magento]]> <![CDATA[SET NAMES utf8]]> <![CDATA[mysql4]]> <![CDATA[pdo_mysql]]> <![CDATA[]]> 1 Cm_Cache_Backend_Redis 127.0.0.1 6379 0 0 1 10 0 1 1 20480 gzip 0 db 127.0.0.1 6379 2.5 0 2048 gzip 1 6 5 10 30 600 60 7200 0 60 2592000 <![CDATA[admin]]> |
Clear all the cache and sessions:
|
1 2 3 |
rm -rf /var/www/html/magento/var/session/* rm -rf /var/www/html/magento/var/cache/* |
Or, log in to the Admin panel as an administrator,
System > Cache Management,
and, click on ‘Flush Magento Cache’.
Now, restart as,
|
1 |
service redis-server restart |
To check if Redis-server is working or not, Enter
|
1 2 |
redis-cli ping |
If result is,
|
1 |
PONG |
Then your server is responding.
Also you can monitor all the traffic by,
|
1 |
redis-cli monitor |
then refresh the page. If you can see logs generating on your terminal, having random alphanumeric characters, then it means caching is working.
You can also check if Redis-server is able to set keys or not,
|
1 2 3 4 5 6 7 8 |
redis-cli 127.0.0.1:6379> set mykey KEY OK 127.0.0.1:6379> get mykey "KEY" 127.0.0.1:6379> exit |
You can also use ‘info’ command to get information and statistics about the server as,
|
1 |
redis-cli info |
