Don't use Redis logical databases

This commit is contained in:
Buster Neece 2024-01-12 03:40:39 -06:00
parent 7d0851122b
commit 0bfd947f9c
No known key found for this signature in database
5 changed files with 15 additions and 24 deletions

View File

@ -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

View File

@ -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()) {

View File

@ -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',

View File

@ -57,7 +57,7 @@ final class QueueManager extends AbstractQueueManager
'redeliver_timeout' => 43200,
'claim_interval' => 86400,
],
$this->redisFactory->createInstance()
$this->redisFactory->getInstance()
);
}

View File

@ -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;
}
}