Using a Redis Server
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 overridesconcrete.cache.levels.expensive
a cache used to store data that should be kept across different web requests (it's thecache/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 thecache
described here)
Concrete supports 2 different type of connection to a redis server:
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 ]
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,
],
],
],
],
],
];