diff --git a/config/services.php b/config/services.php index 12727c55a..b4454042c 100644 --- a/config/services.php +++ b/config/services.php @@ -155,7 +155,7 @@ return [ $cacheInterface = new Symfony\Component\Cache\Adapter\ArrayAdapter(); } elseif ($redisFactory->isSupported()) { $cacheInterface = new Symfony\Component\Cache\Adapter\RedisAdapter( - $redisFactory->createInstance(), + $redisFactory->getInstance(), marshaller: new Symfony\Component\Cache\Marshaller\DefaultMarshaller( $environment->isProduction() ? null : false ) @@ -190,7 +190,7 @@ return [ Environment $environment, App\Service\RedisFactory $redisFactory ) => ($redisFactory->isSupported()) - ? new Symfony\Component\Lock\Store\RedisStore($redisFactory->createInstance()) + ? new Symfony\Component\Lock\Store\RedisStore($redisFactory->getInstance()) : new Symfony\Component\Lock\Store\FlockStore($environment->getTempDirectory()), // Console diff --git a/src/Environment.php b/src/Environment.php index a2d034299..f87f5eb38 100644 --- a/src/Environment.php +++ b/src/Environment.php @@ -71,7 +71,6 @@ final class Environment public const ENABLE_REDIS = 'ENABLE_REDIS'; public const REDIS_HOST = 'REDIS_HOST'; public const REDIS_PORT = 'REDIS_PORT'; - public const REDIS_DB = 'REDIS_DB'; public function __construct(array $elements = []) { @@ -368,7 +367,6 @@ final class Environment * @return array{ * host: string, * port: int, - * db: int, * socket?: string * } */ @@ -384,10 +382,6 @@ final class Environment $this->data[self::REDIS_PORT] ?? null, 6379 ), - 'db' => Types::int( - $this->data[self::REDIS_DB] ?? null, - 1 - ), ]; if ('localhost' === $redisSettings['host'] && $this->isDocker()) { diff --git a/src/Installer/EnvFiles/AzuraCastEnvFile.php b/src/Installer/EnvFiles/AzuraCastEnvFile.php index a49b9a0ef..eaa7ea4a1 100644 --- a/src/Installer/EnvFiles/AzuraCastEnvFile.php +++ b/src/Installer/EnvFiles/AzuraCastEnvFile.php @@ -182,12 +182,6 @@ final class AzuraCastEnvFile extends AbstractEnvFile 'default' => $redisSettings['port'], 'required' => true, ], - Environment::REDIS_DB => [ - 'name' => __('Redis Database Index'), - 'options' => range(0, 15), - 'default' => $redisSettings['db'], - 'required' => true, - ], 'PHP_MAX_FILE_SIZE' => [ 'name' => __('PHP Maximum POST File Size'), 'default' => '25M', diff --git a/src/MessageQueue/QueueManager.php b/src/MessageQueue/QueueManager.php index 4185f35f4..fcdcc997d 100644 --- a/src/MessageQueue/QueueManager.php +++ b/src/MessageQueue/QueueManager.php @@ -57,7 +57,7 @@ final class QueueManager extends AbstractQueueManager 'redeliver_timeout' => 43200, 'claim_interval' => 86400, ], - $this->redisFactory->createInstance() + $this->redisFactory->getInstance() ); } diff --git a/src/Service/RedisFactory.php b/src/Service/RedisFactory.php index 45fc2bf02..8a95e1bab 100644 --- a/src/Service/RedisFactory.php +++ b/src/Service/RedisFactory.php @@ -12,27 +12,30 @@ final class RedisFactory { use EnvironmentAwareTrait; + protected ?Redis $instance = null; + public function isSupported(): bool { return !$this->environment->isTesting() && $this->environment->enableRedis(); } - public function createInstance(): Redis + public function getInstance(): Redis { if (!$this->isSupported()) { throw new RuntimeException('Redis is disabled on this installation.'); } - $settings = $this->environment->getRedisSettings(); + if (null === $this->instance) { + $settings = $this->environment->getRedisSettings(); - $redis = new Redis(); - if (isset($settings['socket'])) { - $redis->connect($settings['socket']); - } else { - $redis->connect($settings['host'], $settings['port'], 15); + $this->instance = new Redis(); + if (isset($settings['socket'])) { + $this->instance->connect($settings['socket']); + } else { + $this->instance->connect($settings['host'], $settings['port'], 15); + } } - $redis->select($settings['db']); - return $redis; + return $this->instance; } }