Set up the 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

Relationship

The format exposed in the $MAGENTO_CLOUD_RELATIONSHIPS follows:

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

Usage example

In your .magento/services.yaml:

myredis:
    type: redis:3.0

You can also use the following:

cache:
    type: redis:3.0

In your .magento.app.yaml, configure the relationship and enable the PHP redis extension if you are using PHP:

runtime:
    extensions:
        - redis

relationships:
    redis: "myredis:redis"

You can then use the service in a configuration file of your application as follows:

if (getenv('MAGENTO_CLOUD_RELATIONSHIPS')) {
    $relationships = json_decode(base64_decode(getenv('MAGENTO_CLOUD_RELATIONSHIPS')), true);

    foreach ($relationships['redis'] as $endpoint) {
        $container->setParameter('redis_host', $endpoint['host']);
        $container->setParameter('redis_port', $endpoint['port']);
    }
}

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.

redis-cli -h redis.internal