Skip to content

Commit

Permalink
Merge pull request #256 from City-of-Helsinki/develop
Browse files Browse the repository at this point in the history
added redis related settings
  • Loading branch information
rpnykanen authored Apr 29, 2022
2 parents 0a26a28 + b64be48 commit 002b9e4
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions public/sites/default/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,44 @@
}
}

if (
($redis_host = getenv('REDIS_HOST')) &&
file_exists('modules/contrib/redis/redis.services.yml') &&
extension_loaded('redis')
) {
// Redis namespace is not available until redis module is enabled, so
// we have to manually register it in order to enable the module and have
// this configuration when the module is installed, but not yet enabled.
$class_loader->addPsr4('Drupal\\redis\\', 'modules/contrib/redis/src');
$redis_port = getenv('REDIS_PORT') ?: 6379;

if ($redis_prefix = getenv('REDIS_PREFIX')) {
$settings['cache_prefix']['default'] = $redis_prefix;
}

if ($redis_password = getenv('REDIS_PASSWORD')) {
$settings['redis.connection']['password'] = $redis_password;
}
$settings['redis.connection']['interface'] = 'PhpRedis';
$settings['redis.connection']['port'] = $redis_port;

// REDIS_INSTANCE environment variable is used to support Redis sentinel.
// REDIS_HOST value should contain host and port, like 'sentinel-external:5000'
// when using Sentinel.
if ($redis_instance = getenv('REDIS_INSTANCE')) {
$settings['redis.connection']['instance'] = $redis_instance;
// Sentinel expects redis host to be an array.
$redis_host = explode(',', $redis_host);
}
$settings['redis.connection']['host'] = $redis_host;

$settings['cache']['default'] = 'cache.backend.redis';
$settings['container_yamls'][] = 'modules/contrib/redis/example.services.yml';
// Register redis services to make sure we don't get a non-existent service
// error while trying to enable the module.
$settings['container_yamls'][] = 'modules/contrib/redis/redis.services.yml';
}

if ($env = getenv('APP_ENV')) {
$settings['ASU_ELASTICSEARCH_ADDRESS'] = getenv('ASU_ELASTICSEARCH_ADDRESS') ?? 'http://elastic:9200';

Expand Down

0 comments on commit 002b9e4

Please sign in to comment.