Set up Redis service

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

More information about Redis

We support Redis versions 2.8 and 3.0.

Redis 3.0 supports up to 64 different databases per instance of the service, while 2.8 allows for only a single database.

Add Redis in services.yaml and .magento.app.yaml

To enable Redis, add the following code with your installed version and allocated disk space in MB to .magento/services.yaml.

myredis:
    type: redis:3.0

If you want to provide your own Redis configuration, you can add a core_config key in your .magento/services.yaml:

cache:
    type: redis:3.0

To configure the relationships for the environment variable, set a relationship in your .magento.app.yaml in the Git branch. For example:

runtime:
    extensions:
        - redis

relationships:
    redis: "myredis:redis"

Merge and deploy the code to set the configurations for Redis. For information on how these changes affect your environments, see services.yaml.

Verify environment-related relationships

We use the Magento Commerce (Cloud) environment variable $MAGENTO_CLOUD_RELATIONSHIPS, a JSON object, to retrieve environment-related relationships.

To verify this information used for configurations and settings:

  1. SSH into the Development (Integration) environment with Redis installed and configured.
  2. Enter the following command to pretty-print connection information for Redis:

     php -r 'print_r(json_decode(base64_decode($_ENV["MAGENTO_CLOUD_RELATIONSHIPS"])));'
    

The response includes all relationships for services and configuration data for that environment. In the response, you will locate data similar to the following for Redis:

{
    "redis": [
        {
            "host": "192.0.2.55",
            "scheme": "redis",
            "port": 6379
        }
    ]
}

Using redis-cli to access your Redis service

Assuming your Redis relationship is named redis, you can access it by opening an SSH tunnel to a host named redis.internal using the redis-cli tool.

  1. SSH into the Development (Integration) environment with RabbitMQ installed and configured.
  2. Enter the following command:

     redis-cli -h redis.internal