Using Redis for Cache Backend in Magento
Magento currently supports many cache back end with file system. But when there is high traffic your eCommerce website suffers with poor scaling problem. Not only this some of the back end implementations have serious limitations like lack of grouping of related cache entries support, commonly known as tagging.
Redis is an open source platform that can be used optionally by Magento eCommerce websites for back end and session storage instead of using Memcache. By using Redis, one can enable on-disk saving and replication, which is not supported by Memchache. Redis also helps in PHP session storage and eviction control, it supports multiple databases that uses same server instance, and also supports compression libraries making performance faster.
Problems with Two Levels Cache Back end
Generally, Magento users go for Two Levels Cache back end as it is available in Magento as default, which is a combination of one fast and one slow caching method. The fast cache uses Memcache whereas slow one uses some file system. In case one runs multiple web nodes, this is achieved using Memcache along with some database. But this type of back end process has some problems:
- The core_cache_tag table on an average holds about 5 million records for each website. In case of multiple web-stores having large catalogs, it might become 3 or 4 times in just one day. This might create problems in MySQL server, thus degrading overall performance.
- Memchache has certain limitations related to maximum size of object and fixed bucket size making things difficult to maintain.
- Two Levels back end do not scale properly, as it uses database that adds load to the master database server.
Benefits of Using Redis Cache Backend
One can integrate Magento Enterprise edition and Community edition with Redis with minimum changes in configuration. The benefits of using cache back end and Redis server were:
- Redis supports different data and is easy to implement using SET and HASH tagging system objects.
- It supports tagging based cache cleanup without using for-each loops.
- It is recommended in case of multi-server environment where there will be more than one web server.
- Redis supports on disk saving and also master/slave replication features that is not supported in Memcache. This helps in avoiding failure.
- Redis offers better eviction control and its back end coding is done with eviction support under consideration.
- Redis database is easy to save and can easily loaded in a development environment. It also makes debugging simple.
- It supports monitoring functionality, where one can watch requests in real-time. This will help in spotting bugs in any application both in case of using Redis as database or using it as distributed caching system.
- When Redis was tested in high traffic Magento store having more than 500,000 visitors a day, it was stable and had a great performance.
To use Redis in your Magento website, you must install and configure the Redis server as the integration between Magento and Redis is already provided in the latest versions of Magento. Next you need to enable Cm_RedisSession module as it is disabled by default. Then login to Magento Admin Panel, and click on Flush Magento Cache attribute available in Cache Management tab in System menu.
Redis includes a few tools like client software accessible trough. After you start Redis client, you need to enter supported commands in the Redis console. Some of the commonly used commands include:
- FLUSHALL – This command clears all database
- SELECT # – This command will select database under the index #
- FLUSHDB – It will empty the current selected database
- KEYS * – It will list all the keys from current selected database
The main advantage of Redis is that databases are created based on demand and they can be indexed only by integers. Redis solves problems that affect cache back ends, still cleaning-up old cache tags is to be done manually. For this, Magento provides garbage cleanup PHP script designed to solve this issue.
So try out implementing Redis with Magento. It really helps!!
[We are Connecting Dots, a full service eCommerce solutions company. At Connecting Dots, we help companies build great online businesses, we are Magento implementation partners and build great eCommerce portals]