Skip to content

[3.x]: Craft is not working when Redis server is down #11360

Discussion options

You must be logged in to vote

You could accomplish this by setting your cache component config to a callback function, which checks whether Redis is running, and if not, fallback to file (or DB) caching.

return [
    'components' => [
        'cache' => function() {
            try {
                Craft::$app->redis->open();
                $useRedis = true;
            } catch (yii\db\Exception $e) {
                $useRedis = false;
            }

            if ($useRedis) {
                $config = [
                    'class' => yii\redis\Cache::class,
                    'defaultDuration' => 86400,
                    'keyPrefix' => craft\helpers\App::env('APP_ID') ?: 'CraftCMS',
                ];
        …

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@martinhellwagner
Comment options

Answer selected by brandonkelly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
2 participants
Converted from issue

This discussion was converted from issue #11356 on May 31, 2022 23:34.