Skip to content

Redis Cache Configuration

All Stratus Magento stores are required to have cache enabled on Production instances and to use Redis for storage cache and Varnish cache for Magento 2 Full Page Cache.

MageMojo Stratus does not allow cache to be stored in files or the database.

Redis caches are controlled and configured in the Redis section of the Stratus Control panel.

Accessing Redis Cache via SSH

The Stratus Redis services are accessible directly via SSH:

redis-cli -h redis -p 6379
redis-cli -h redis-config-cache -p 6381
redis-cli -h redis-session -p 6380

In addition to the Stratus Control panel, Redis commands can be used to control the Redis cache on the Stratus install. With exception to Varnish for the Magento 2 FPC, Redis is recommended for all caches on Mojo Stratus.

Configuring Redis Caches

Redis Full Page Cache and Redis Sessions must be enabled in the Stratus Control panel.

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

Magento 1

Add the following to the Magento local.xml configuration, then flush the cache to apply the change.

Check the developer document for any 3rd party FPC module. Most support Redis. The Redis Config Cache container can be enabled in Redis > Config Cache in the Stratus Control panel.

xml
<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 Full Page Cache (Magento 1.x Enterprise Edition 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>

Enabling Caches

The caches can be enabled using commands via SSH:

  • Magento 1 — n98-magerun cache:enable
  • Magento 2 — n98-magerun2 cache:enable

Flushing Caches

Redis caches may need to be cleared during development or to troubleshoot a site issue. Redis cache can be flushed via SSH:

bash
redis-cli -h redis -p 6379 FLUSHALL
redis-cli -h redis-config-cache -p 6381 FLUSHALL
redis-cli -h redis-session -p 6380 FLUSHALL

Note: Redis cache sessions will NOT be cleared by the command /user/share/stratus/cli-cache.all.clear nor will they clear during a redeployment.