Configure Redis

Overview of the Redis solution

Redis is an optional backend cache solution to replace Zend_Cache_Backend_File, which is used in Magento 2 by default.

Issues with Zend_Cache_Backend_File

  • The core_cache_tag table constantly grows. If a Magento instance has multiple web sites and web stores with large catalogs, the table can grow to 15 million records in less than a day. Insertion into core_cache_tag leads to issues with MySQL server, including performance degradation.

    (A tag is an identifier that classifies different types of Magento cache objects.)

  • The TwoLevels backend is more difficult to maintain because two services are required to make it work which makes it difficult to analyze cache content when necessary.
    Further, memcached itself has limitations such as a maximum object size and fixed bucket sizes which also contribute to difficult maintenance.

  • The Zend TwoLevels backend does not scale well because using the database as part of the cache backend adds additional load to the master database server. Additionally, there is no reliable method for memcached replication.

Why Redis is better

Advantages of Redis include:

  • Redis can also be used for PHP session storage, making it possible to completely replace memcached with Redis.

  • The Redis backend works by indexing tags in files so that tag operations do not require a full scan of every cache file.

  • The metadata and the cache record are stored in the same file rather than separate files resulting in fewer inodes and fewer file stat, read, write, lock, and unlink operations. Also, the original hashed directory structure had very poor distribution due to the adler32 hashing algorithm and prefixes. The multi-level nested directories have been dropped in favor of single-level nesting made from multiple characters.

  • The backend supports tag-based cache cleanup without foreach loops.

  • Redis supports on-disk save and master/slave replication.

    This is a highly requested feature that is not supported by memcached. Replication avoids a single point of failure and provides high availability.

Starting in Magento 2.0.6, you can use either Redis or memcached for session storage. Earlier issues with the Redis session handler and session locking have been resolved.

Install Redis

Installing and configuring the Redis software is beyond the scope of this guide. Consult resources such as:

For more information

You can find more information about configuring Redis from the following:

Next