diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 5935e89..5d17e2f 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -4,6 +4,7 @@ namespace App\Providers; use App\Support\ManagedCredentialFiles; use App\Support\ManagedPhpRedisConnector; +use App\Support\ManagedPredisConnector; use Carbon\CarbonImmutable; use Illuminate\Database\DatabaseManager; use Illuminate\Redis\RedisManager; @@ -25,12 +26,13 @@ class AppServiceProvider extends ServiceProvider return; } + $redisClient = $config->get('database.redis.client'); if ($config->get('database.default') !== 'mysql' - || $config->get('database.redis.client') !== 'phpredis' + || ! in_array($redisClient, ['phpredis', 'predis'], true) || $config->get('database.connections.mysql.url') || $config->get('database.redis.default.url') || $config->get('database.redis.cache.url')) { - throw new RuntimeException('Managed credentials require the supported MySQL and standalone PhpRedis connections.'); + throw new RuntimeException('Managed credentials require the supported MySQL and standalone Redis connections.'); } $this->callAfterResolving('db', function (DatabaseManager $manager): void { @@ -41,8 +43,10 @@ class AppServiceProvider extends ServiceProvider }); }); - $this->callAfterResolving('redis', function (RedisManager $manager): void { - $manager->extend('phpredis', fn () => new ManagedPhpRedisConnector); + $this->callAfterResolving('redis', function (RedisManager $manager) use ($redisClient): void { + $manager->extend($redisClient, fn () => $redisClient === 'predis' + ? new ManagedPredisConnector + : new ManagedPhpRedisConnector); }); } diff --git a/app/Support/ManagedPredisConnector.php b/app/Support/ManagedPredisConnector.php new file mode 100644 index 0000000..5d45778 --- /dev/null +++ b/app/Support/ManagedPredisConnector.php @@ -0,0 +1,30 @@ + $config + * @param array $options + */ + public function connect(array $config, array $options) + { + $config['password'] = ManagedCredentialFiles::redisPassword(); + + return parent::connect($config, $options); + } + + /** + * @param array $config + * @param array $clusterOptions + * @param array $options + */ + public function connectToCluster(array $config, array $clusterOptions, array $options): never + { + throw new RuntimeException('Managed credential delivery requires standalone Redis.'); + } +}