Skip to content

Commit

Permalink
Handle the CACHE_STORE env var for Laravel 11+
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasdiluccio committed May 29, 2024
1 parent 1e3312f commit de1775f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ php artisan cache:clear

* If a Platform.sh relationship named `database` is defined, it will be taken as an SQL database and mapped to the `DB_*` environment variables for Laravel.

* If a Platform.sh relationship named `rediscache` is defined, it will be mapped to the `REDIS_*` environment variables for Laravel. Additionally, the `CACHE_DRIVER` variable will be set to `redis` to activate it automatically.
* If a Platform.sh relationship named `rediscache` is defined, it will be mapped to the `REDIS_*` environment variables for Laravel. Additionally, the `CACHE_DRIVER` (up to Laravel v10) and `CACHE_STORE` (Laravel v11+) variables will be set to `redis` to activate it automatically.

* If a Platform.sh relationship named `redissession` is defined, the `SESSION_DRIVER` will be set to `redis` and the `REDIS_*` variables set based on that relationship. NOTE: This means you _*must*_ set 2 relationships to the same Redis service and endpoint, as Laravel reuses the same backend connection.

Expand Down
3 changes: 2 additions & 1 deletion platformsh-laravel-env.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ function mapPlatformShRedisCache(string $relationshipName, Config $config) : voi

$credentials = $config->credentials($relationshipName);

setEnvVar('CACHE_DRIVER', 'redis');
setEnvVar('CACHE_DRIVER', 'redis'); // Compatible with Laravel v10 and below
setEnvVar('CACHE_STORE', 'redis'); // Compatibile with Laravel v11+
setEnvVar('REDIS_CLIENT', 'phpredis');
setEnvVar('REDIS_HOST', $credentials['host']);
setEnvVar('REDIS_PORT', $credentials['port']);
Expand Down
2 changes: 2 additions & 0 deletions tests/LaravelBridgeRedisCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public function test_no_rediscache_relationship_set_does_nothing() : void
$this->assertFalse(getenv('REDIS_HOST'));
$this->assertFalse(getenv('REDIS_PORT'));
$this->assertFalse(getenv('CACHE_DRIVER'));
$this->assertFalse(getenv('CACHE_STORE'));
}

public function test_rediscache_relationship_gets_mapped() : void
Expand All @@ -87,6 +88,7 @@ public function test_rediscache_relationship_gets_mapped() : void
$rel = $this->relationships['rediscache'][0];

$this->assertEquals('redis', getenv('CACHE_DRIVER'));
$this->assertEquals('redis', getenv('CACHE_STORE'));
$this->assertEquals('phpredis', getenv('REDIS_CLIENT'));
$this->assertEquals($rel['host'], getenv('REDIS_HOST'));
$this->assertEquals($rel['port'], getenv('REDIS_PORT'));
Expand Down

0 comments on commit de1775f

Please sign in to comment.