- Add DISCOVERY_LOG_LEVEL=debug - Add DISCOVERY_SHOW_PROGRESS=true - Temporary changes for debugging InitializerProcessor fixes on production
77 lines
2.1 KiB
PHP
77 lines
2.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Framework\Redis;
|
|
|
|
/**
|
|
* Configuration for Redis connections
|
|
*/
|
|
final readonly class RedisConfig
|
|
{
|
|
public function __construct(
|
|
public string $host = 'redis',
|
|
public int $port = 6379,
|
|
public ?string $password = null,
|
|
public int $database = 0,
|
|
public float $timeout = 1.0,
|
|
public float $readWriteTimeout = 1.0,
|
|
public string $scheme = 'tcp',
|
|
public array $options = []
|
|
) {
|
|
}
|
|
|
|
/**
|
|
* Create configuration from environment variables or defaults
|
|
*/
|
|
public static function fromEnvironment(string $prefix = 'REDIS_'): self
|
|
{
|
|
return new self(
|
|
host: $_ENV[$prefix . 'HOST'] ?? 'redis',
|
|
port: (int) ($_ENV[$prefix . 'PORT'] ?? 6379),
|
|
password: $_ENV[$prefix . 'PASSWORD'] ?? null,
|
|
database: (int) ($_ENV[$prefix . 'DB'] ?? 0),
|
|
timeout: (float) ($_ENV[$prefix . 'TIMEOUT'] ?? 1.0),
|
|
readWriteTimeout: (float) ($_ENV[$prefix . 'READ_WRITE_TIMEOUT'] ?? 1.0)
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Create a new config with different database
|
|
*/
|
|
public function withDatabase(int $database): self
|
|
{
|
|
return new self(
|
|
host: $this->host,
|
|
port: $this->port,
|
|
password: $this->password,
|
|
database: $database,
|
|
timeout: $this->timeout,
|
|
readWriteTimeout: $this->readWriteTimeout,
|
|
scheme: $this->scheme,
|
|
options: $this->options
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Convert to Predis connection parameters
|
|
*/
|
|
public function toConnectionParameters(): array
|
|
{
|
|
$params = [
|
|
'scheme' => $this->scheme,
|
|
'host' => $this->host,
|
|
'port' => $this->port,
|
|
'database' => $this->database,
|
|
'timeout' => $this->timeout,
|
|
'read_write_timeout' => $this->readWriteTimeout,
|
|
];
|
|
|
|
if ($this->password) {
|
|
$params['password'] = $this->password;
|
|
}
|
|
|
|
return array_merge($params, $this->options);
|
|
}
|
|
}
|