Performance

Implementing Redis on Magento 2

By 13th June 2017October 9th, 20204 Comments

Magento 2 comes with native Redis support, so it is not necessary to install any supporting dependencies like on Magento 1. You just need to add the respective configuration to the Magento ./app/etc/env.php

Cache and full page cache storage

There are three elements to add for Redis; cache, full page cache and sessions.

Add the following after the opening array statement,

    'cache' => [
        'frontend' => [
            'default' => [
                'backend' => 'Cm_Cache_Backend_Redis',
                'backend_options' =>
                    [
                        'server' => 'redis11.i',
                        'database' => '0',
                        'port' => '6379',
                        'compress_data' => '1',
                        'compression_lib' => 'gzip'
                    ],
            ],
            'page_cache' => [
                'backend' => 'Cm_Cache_Backend_Redis',
                'backend_options' =>
                    [
                        'server' => 'redis31.i',
                        'port' => '6380',
                        'database' => '0',
                        'compress_data' => '1',
                        'compression_lib' => 'gzip'
                    ]
            ]
        ]
    ],

Session storage

Replace the following,

    'session' => [
        'save' => 'files',
    ],

With,

    'session' => [
        'save' => 'redis',
        'redis' => [
            'host' => 'redis1.i',
            'port' => '6379',
            'password' => '',
            'timeout' => '2.5',
            'persistent_identifier' => '',
            'database' => '0',
            'compression_threshold' => '2048',
            'compression_library' => 'gzip',
            'log_level' => '1',
            'max_concurrency' => '6',
            'break_after_frontend' => '5',
            'break_after_adminhtml' => '30',
            'first_lifetime' => '600',
            'bot_first_lifetime' => '60',
            'bot_lifetime' => '7200',
            'disable_locking' => '1',
            'min_lifetime' => '60',
            'max_lifetime' => '2592000'
        ]
    ],