Using a Redis Server

This is a community-contributed tutorial. This tutorial is over a year old and may not apply to your version of Concrete CMS.
Jun 16, 2023

By default, Concrete stores non-volatile cache items in the filesystem (in the /application/files/cache directory).

If you want to use a redis server instead, you have to manually edit the /application/config/concrete.php file, where you can define how the different persistent caches have to be stored.

Concrete caches

You can use Redis instead of the filesystem cache with these configuration keys:

  • concrete.cache.levels.overrides a cache used to store the resolved overrides
  • concrete.cache.levels.expensive a cache used to store data that should be kept across different web requests (it's the cache/expensive described here)
  • concrete.cache.levels.object this is usually a cache that's ephemeral, but you may want to use a persistent driver for it (it's the cache described here)

Concrete supports 2 different type of connection to a redis server:

  1. To define connection via TCP/IP, you can use an array like this:

    [
       'host' => '127.0.0.1', // The IP or the host name of the Redis server
       'port' => 6379, // The TCP port to be used, you can omit it if you use the default port (6379)
       'ttl' => 5, // The connection timeout (in seconds)
       'password' => null, // The password to be used to connect to the Redis server, omit or set to null if none
    ]
    
  2. To define connection via Unix socket, you can use an array like this:

    [
       'socket' => '/run/redis/redis.sock',
       'password' => null, // The password to be used to connect to the Redis server, omit or set to null if none
    ]
    

Concrete supports connecting to multiple Redis servers, and the definition of all the server connections must be stored in a servers configuration key. In addition, if your Redis server serves multiple applications or websites, you may also want to specify which database to be used (via a database configuration key), as well as a prefix for the keys of the cached items (via a prefix configuration key). You finally have to set the preferred_driver configuration key to redis in order to instruct Concrete to use the Redis servers instead of the filesystem.

To summarize, here's an extract from a sample /application/config/concrete.php file that configure Redis for the Concrete caches:

<?php

return [
    'cache' => [
        'levels' => [
            'overrides' => [
                'preferred_driver' => 'redis',
                'drivers' => [
                    'redis' => [
                        'options' => [
                            'database' => 0,
                            'prefix' => 'myapp:overrides',
                            'servers' => [
                                [
                                    'host' => '127.0.0.1',
                                    'port' => 6379,
                                    'ttl' => 5,
                                    'password' => null,
                                ],
                            ],
                        ],
                    ],
                ],
            ],
            'expensive' => [
                'preferred_driver' => 'redis',
                'drivers' => [
                    'redis' => [
                        'options' => [
                            'database' => 0,
                            'prefix' => 'myapp:expensive',
                            'servers' => [
                                [
                                    'host' => '127.0.0.1',
                                    'port' => 6379,
                                    'ttl' => 5,
                                    'password' => null,
                                ],
                            ],
                        ],
                    ],
                ],
            ],
            'object' => [
                'preferred_driver' => 'redis',
                'drivers' => [
                    'redis' => [
                        'options' => [
                            'database' => 0,
                            'prefix' => 'myapp:object',
                            'servers' => [
                                [
                                    'host' => '127.0.0.1',
                                    'port' => 6379,
                                    'ttl' => 5,
                                    'password' => null,
                                ],
                            ],
                        ],
                    ],
                ],
            ],
        ],
    ],
];

Session storage

You can use Redis instead of the filesystem to store the data of your visitor sessions. The definition of the Redis server(s) to be used must be done using the concrete.session.redis configuration key (its definition is the same as above), and you have to set the concrete.session.handler to redis.

Here's an extract from a sample /application/config/concrete.php file that configure Redis for the session data:

<?php

return [
    'session' => [
        'handler' => 'redis',
        'redis' => [
            'database' => 0,
            'prefix' => 'myapp:session',
            'servers' => [
                [
                    'host' => '127.0.0.1',
                    'port' => 6379,
                    'ttl' => 5,
                    'password' => null,
                ],
            ],
        ],
    ],
];

Page cache

In order to instruct Concrete to use Redis to store the cached pages, you can configure the concrete.cache.page.redis configuration key as described above, and set the concrete.cache.page.adapter configuration key to redis. You can configure the prefix with the prefix key,

Here's an extract from a sample /application/config/concrete.php file that configure Redis for the page cache:

<?php

return [
    'cache' => [
        'page' => [
            'adapter' => 'redis',
            'redis' => [
                'prefix' => 'myapp:page-cache',
                'database' => 0,
                'servers' => [
                    [
                        'host' => '127.0.0.1',
                        'port' => 6379,
                        'ttl' => 5,
                        'password' => null,
                    ],
                ],
            ],
        ],
    ],
];
Recent Tutorials
Customize the default page title
Mar 12, 2025

Change the default " :: " and/or "site name :: page title" formatting separator to something else.

Configure Composer to work with a Page Type
Feb 20, 2025
By myq.

Fix the "Unable to load block into composer. You must edit this content from within the context of the page." error message

Permissions for editors in a multilingual site
Feb 2, 2025
By myq.

How to set up a multilingual Concrete CMS site for groups of language-specific editors

Restoring deleted pages using advanced search
Jan 16, 2025
By myq.

How to recover deleted pages when there are more than a few to choose from.

How to Automate the Copyright Year
Dec 27, 2024

Learn how to keep your website's copyright year updated automatically in Concrete CMS.

How to change the path of a group of pages
Dec 23, 2024
By myq.

Change the canonical path without breaking things

Improvements?

Let us know by posting here.