-
Notifications
You must be signed in to change notification settings - Fork 684
Closed as duplicate of#754
Labels
Description
What happened?
Description
Setting up a site to use REDIS for cache storage and get an error when following the docs.
I add (as per docs) the following to app.php:
'components' => [
'cache' => function() {
$config = [
'class' => yii\redis\Cache::class,
'keyPrefix' => Craft::$app->id,
'defaultDuration' => Craft::$app->config->general->cacheDuration,
// Full Redis connection details:
'redis' => [
'hostname' => App::env('REDIS_HOSTNAME') ?: 'localhost',
'port' => 6379,
'password' => App::env('REDIS_PASSWORD') ?: null,
],
];
return Craft::createObject($config);
},
],Then get the error detailed below.
Discussing with the fellow AI, the suggestion is to use this instead:
'components' => [
'redis' => [
'class' => yii\redis\Connection::class,
'hostname' => App::env('REDIS_HOSTNAME') ?: 'localhost',
'port' => App::env('REDIS_PORT') ?: 6379,
'password' => App::env('REDIS_PASSWORD') ?: null,
'database' => App::env('REDIS_DB') ?: 0,
],
'cache' => [
'class' => yii\redis\Cache::class,
'redis' => 'redis',
'defaultDuration' => 86400,
],
],Steps to reproduce
Expected behavior
No error
Actual behavior
Error returned on every page:
An Error occurred while handling another error:
yii\di\NotInstantiableException: Can not instantiate yii\redis\ConnectionInterface. in /project/location/project-name/vendor/yiisoft/yii2/di/Container.php:408
Craft CMS version
5.8.20
PHP version
8.4
Operating system and version
MacOS 15.7.3 and Ubuntu 24
Database type and version
MySQL 8.0
Reactions are currently unavailable