I've read How can I check if a module is enabled? and How can we use \Drupal class inside Settings.php and came to the conclusion that I cannot use the module_handler service in settings.php.
How can I check if a module -- in this case the redis module -- is enabled in settings.php?
Context
I am using docker for a Drupal 9.4 installation. When I initialize a new container from the image, and I install Drupal (initialize a new database), the redis module isn't initially activated, although present.
This means I cannot initially specify $settings['cache']['default'] = 'cache.backend.redis';
in settings.php (it will make the system crash).
I would have like to do
$moduleHandler = \Drupal::service('module_handler');
if ($moduleHandler->moduleExists('redis')) {
$settings['cache']['default'] = 'cache.backend.redis';
}
Of course this doesn't work and I understand why. But I would like to avoid going into my container to edit settings.php after activating the redis module every time I start a new container.