Skip to content

Enabling Redis Cache

Redis should be used for all caching with exception to Varnish for the FPC in Magento 2 (or customized Varnish uses or Turpentine with Magento 1). Please note that redis-config-cache and redis-session must be turned on in the stratus panel.

Files cache is very BAD!

Magento 2

Use the following commands via CLI:

Redis Cache

php bin/magento setup:config:set --cache-backend=redis --cache-backend-redis-server=redis-config-cache --cache-backend-redis-db=0 --cache-backend-redis-port=6381

Redis FPC

php bin/magento setup:config:set --page-cache=redis --page-cache-redis-server=redis --page-cache-redis-db=0 --page-cache-redis-port=6379

Redis Session

php bin/magento setup:config:set --session-save=redis --session-save-redis-host=redis-session --session-save-redis-log-level=3 --session-save-redis-db=0 --session-save-redis-port=6380

You can also configure by adding this directly to your Magento 2 env.php configuration, then flush the cache to apply it.

<? php
'cache' =>
array(
   'frontend' =>
   array(
      'default' =>
      array(
         'backend' => 'Cm_Cache_Backend_Redis',
         'backend_options' =>
         array(
            'server' => 'redis-config-cache',
            'database' => '0',
            'port' => '6381'
            ),
    ),
    'page_cache' =>
    array(
      'backend' => 'Cm_Cache_Backend_Redis',
      'backend_options' =>
       array(
         'server' => 'redis',
         'port' => '6379',
         'database' => '0',
         'compress_data' => '1'
       )
    )
  )
),
?>

Magento 1

Add this to your Magento local.xml configuration, then flush the cache to apply it.  Note that you can skip the full page block if you are not using Magento 1 EE. Check the developer document for any 3rd party FPC module. Most support Redis. You can enable/disable the redis config cache container under Redis->Config Cache.

<cache>
  <backend_options>
    <server><![CDATA[redis]]></server>
    <port><![CDATA[6379]]></port>
    <persistent><![CDATA[]]></persistent>
    <database><![CDATA[0]]></database>
    <password><![CDATA[]]></password>
    <connect_retries><![CDATA[1]]></connect_retries>
    <read_timeout><![CDATA[10]]></read_timeout>
    <automatic_cleaning_factor><![CDATA[0]]></automatic_cleaning_factor>
    <compress_data><![CDATA[1]]></compress_data>
    <compress_tags><![CDATA[1]]></compress_tags>
    <compress_threshold><![CDATA[20480]]></compress_threshold>
    <compression_lib><![CDATA[gzip]]></compression_lib>
    <use_lua><![CDATA[0]]></use_lua>
<auto_expire_lifetime>604800</auto_expire_lifetime>
  </backend_options>
  <backend><![CDATA[Cm_Cache_Backend_Redis]]></backend>
</cache>

ADD FOR FPC ( Enterprise only )

<full_page_cache>
<backend>Cm_Cache_Backend_Redis</backend>
    <backend_options>
    <server>redis-config-cache</server> <!-- or absolute path to unix socket -->
    <port>6381</port>
    <persistent></persistent> <!-- Specify unique string to enable persistent connections. E.g.: sess-db0; bugs with phpredis and php-fpm are known: https://github.com/nicolasff/phpredis/issues/70 -->
    <database>0</database> <!-- Redis database number; protection against accidental data loss is improved by not sharing databases -->
    <password></password> <!-- Specify if your Redis server requires authentication -->
    <force_standalone>0</force_standalone>  <!-- 0 for phpredis, 1 for standalone PHP -->
    <connect_retries>1</connect_retries>    <!-- Reduces errors due to random connection failures -->
    <lifetimelimit>57600</lifetimelimit>    <!-- 16 hours of lifetime for cache record -->
    <compress_data>0</compress_data>        <!-- DISABLE compression for EE FPC since it already uses compression -->
    <auto_expire_lifetime>604800</auto_expire_lifetime> <!-- Force an expiry (Enterprise_PageCache will not set one) -->
    <auto_expire_refresh_on_load></auto_expire_refresh_on_load> <!-- Refresh keys when loaded (Keeps cache primed frequently requested resources) -->
    </backend_options>
</full_page_cache>