EEConf 2024 is around the corner! EEConf 2024
Hi,
Using EE7 (with coilpack).
I have multiple EE7 installs on a single server (staging and live sites) and would normaly define sites using redis with a different DB number - so we don’t have a major data clash.
Example of laravel redis config:
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD'),
'port' => env('REDIS_PORT', 6379),
'database' => env('REDIS_DB', 1), <<------- example DB config
However EE7 doesn’t look to have a DB config option:
$config['redis'] = array(
'host' => '127.0.0.1',
'password' => NULL,
'port' => 6379,
'timeout' => 0
);
Adding ‘database’ to EE config didn’t work.
Am I missing something or is there a workround / feature request?
Thanks!
Hi Mark, thanks for asking this question!
I looked through the code for how we create a Redis connection just to see if there was an undocumented config variable that would work but it doesn’t seem like this is possible right now. This is certainly something we can address though and I just opened an issue on github
Certainly! It seems like ExpressionEngine 7’s Redis configuration doesn’t have a direct option for selecting the database. In such cases, you can consider using Redis prefixes to segregate data between different installations.
Here’s a workaround:
Update Redis Configuration: In your config.php file, you can define different prefixes for each installation.
php Copy code $config[‘redis’] = array( ‘host’ => ‘127.0.0.1’, ‘password’ => NULL, ‘port’ => 6379, ‘timeout’ => 0, ‘prefix’ => ‘site1_’, // Add a unique prefix for each site ); For the second site, you can use a different prefix:
php Copy code $config[‘redis’] = array( ‘host’ => ‘127.0.0.1’, ‘password’ => NULL, ‘port’ => 6379, ‘timeout’ => 0, ‘prefix’ => ‘site2_’, // Different prefix for the second site ); Update Laravel Redis Config (Optional): If your Laravel application also interacts with the same Redis server and you want to segregate data, you can use different prefixes in Laravel’s Redis configuration as you’ve shown in your Laravel example.
php Copy code ‘host’ => env(‘REDIS_HOST’, ‘127.0.0.1’), ‘password’ => env(‘REDIS_PASSWORD’), ‘port’ => env(‘REDIS_PORT’, 6379), ‘database’ => env(‘REDIS_DB’, 1), // Different DB for each site ‘options’ => [ ‘prefix’ => ‘laravel_site1_’, // Laravel prefix for the first site ], Adjust the prefixes accordingly for each site.
This way, by using different prefixes, you can effectively separate data between your ExpressionEngine installations on the same Redis server. Each site will have its own namespace, preventing clashes.
Use environment variables to set the database number dynamically based on the environment (staging or live). This way, you can have different .env files for each environment with a specific database number set for Redis.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.