[3.x]: Craft is not working when Redis server is down #11360
Answered
by
brandonkelly
martinhellwagner
asked this question in
Q&A
-
What happened?DescriptionWe have the problem that Craft is not working when the Redis server is down. Is it possible that Craft is using the DB for caching as fallback when the Redis server is down? Steps to reproduce
Expected behaviorCraft should use the DB for caching when the Redis server is down. Actual behaviorCraft is not working. Craft CMS version3.7.27 PHP version8.0 Operating system and versionNo response Database type and versionNo response Image driver and versionNo response Installed plugins and versionsNo response |
Beta Was this translation helpful? Give feedback.
Answered by
brandonkelly
May 31, 2022
Replies: 1 comment 1 reply
-
You could accomplish this by setting your 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',
];
} else {
$config = craft\helpers\App::cacheConfig();
}
return Craft::createObject($config);
},
],
]; |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
brandonkelly
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.