Skip to content

Instantly share code, notes, and snippets.

@juban
Last active July 11, 2024 17:03
Show Gist options
  • Save juban/6e3bd1eb6a75167a813fc057953b917d to your computer and use it in GitHub Desktop.
Save juban/6e3bd1eb6a75167a813fc057953b917d to your computer and use it in GitHub Desktop.
Redis configuration for Craft CMS
<?php
/**
* Yii Application Config
*
* Edit this file at your own risk!
*
* The array returned by this file will get merged with
* vendor/craftcms/cms/src/config/app/main.php and [web|console].php, when
* Craft's bootstrap script is defining the configuration for the entire
* application.
*
* You can define custom modules and system components, and even override the
* built-in system components.
*/
return [
'components' => [
'cache' => [
'class' => 'yii\redis\Cache',
'defaultDuration' => 86400,
'keyPrefix' => getenv('REDIS_KEYPREFIX').'_cache_',
'redis' => [
'hostname' => getenv('REDIS_HOST'),
'port' => getenv('REDIS_PORT'),
'database' => 0,
'password' => getenv('REDIS_PASSWORD') // Optional
]
],
'session' => [
'class' => 'yii\redis\Session',
'as sessionBehavior' => [
'class' => 'craft\behaviors\SessionBehavior'
],
'keyPrefix' => getenv('REDIS_KEYPREFIX').'_session_',
'redis' => [
'hostname' => getenv('REDIS_HOST'),
'port' => getenv('REDIS_PORT'),
'database' => 1,
'password' => getenv('REDIS_PASSWORD') // Optional
]
],
],
'modules' => [
'siteModule' => \modules\Module::class,
],
'bootstrap' => [
'siteModule',
],
];
@jamesmacwhite
Copy link

Is it necessary to define the redis config twice in the cache and session component?

Can't you define redis as a component itself, given the class for both cache and session are both point to Redis?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment