Contents
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_tagtable 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 intocore_cache_tagleads 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 memcachedreplication.
Why Redis is better
Advantages of Redis include:
- 
    Redis can also be used for PHP session storage, making it possible to completely replace memcachedwith 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 adler32hashing 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 foreachloops.
- 
    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.
We recommend you use memcached for session storage. The Redis session handler in the phpredis PHP extension does not support session locking, which might cause issues with distributed systems and applications that rely on Ajax. We're actively working on a solution.
Install Redis
Installing and configuring the Redis software is beyond the scope of this guide. Consult resources such as:
Configure Magento to use Redis
Following is a sample configuration to add to <your Magento install dir>app/etc/env.php:
'cache' => [
	'frontend' => [
		'page_cache' => [
			'backend' => 'Cm_Cache_Backend_Redis',
			'backend_options' => [
				'server' => '127.0.0.1', 
				'port' => '6379',
				'persistent' => '', 
				'database' => 0, 
				'password' => '', 
				'force_standalone' => 0, 
				'connect_retries' => 1, 
	],
where
| Parameter | Meaning | 
|---|---|
| page_cache | Specify the segment name to use a particular segment or a default shortcut for all other caches. The  | 
| server | Absolute URL to your Redis server, or 127.0.0.1if Redis is installed on the Magento server, or a an absolute path to a UNIX socket. | 
| port | Redis server listen port | 
| persistent | Specify a unique string to enable persistent connections. For example,  Note that there are known issues phpredis and php-fpm. | 
| database | Unique Redis database number, which is recommended to protect against data loss. | 
| password | Specifies a password if your Redis server requires authentication. | 
| force_standalone | Use 0for phpredis or1for standalone PHP. | 
| connect_retries | Reduces errors due to random connection failures. Specify 1to not retry after the first failure. | 
For more information
You can find more information about configuring Redis from the following:
Find us on