We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Define a redis database

How Do I?

Mark Xigen's avatar
Mark Xigen
1 posts
one year ago
Mark Xigen's avatar Mark Xigen

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!

       
Bryan's avatar
Bryan
14 posts
one year ago
Bryan's avatar Bryan

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

       
republicgiant's avatar
republicgiant
1 posts
one year ago
republicgiant's avatar republicgiant

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.

       
Timenot's avatar
Timenot
1 posts
11 months ago
Timenot's avatar Timenot

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.

@block blast

       
gymitat's avatar
gymitat
1 posts
5 months ago
gymitat's avatar gymitat

EE7 doesn’t support specifying the Redis database index natively. As a workaround, you can modify the Redis connection logic to include $redis->select($config[‘redis’][‘database’]); in the caching library. Then, add the database key to your Redis config in config.php. Alternatively, request this feature from the EE team.block blast

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.