%PDF- %PDF-
Server IP : 37.220.80.31 / Your IP : 3.145.44.192 Web Server : Apache/2.4.52 (Ubuntu) System : Linux 3051455-guretool.twc1.net 5.15.0-107-generic #117-Ubuntu SMP Fri Apr 26 12:26:49 UTC 2024 x86_64 User : www-root ( 1010) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /var/www/www-root/data/www/dev.artlot24.ru/bitrix/modules/main/lib/data/configurator/ |
Upload File : |
<?php namespace Bitrix\Main\Data\Configurator; use Bitrix\Main\Application; use Bitrix\Main\NotSupportedException; class RedisConnectionConfigurator { /** @var array */ protected $config; /** @var array */ protected $servers = []; public function __construct($config) { if (!extension_loaded('redis')) { throw new NotSupportedException('redis extension is not loaded.'); } $this->config = $config; $this->addServers($this->getConfig()); } protected function addServers($config) { $servers = $config['servers'] ?? []; if (isset($config['host'], $config['port'])) { array_unshift($servers, [ 'host' => $config['host'], 'port' => $config['port'], ]); } foreach ($servers as $server) { $this->servers[] = [ 'host' => $server['host'] ?? 'localhost', 'port' => $server['port'] ?? '11211', ]; } return $this; } public function getConfig() { return $this->config; } /** * @param \Redis|\RedisCluster $connection */ protected function configureConnection($connection): void { $config = $this->getConfig(); if ($connection instanceof \Redis) { $connection->setOption(\Redis::OPT_SERIALIZER, $config['serializer'] ?? \Redis::SERIALIZER_IGBINARY); } elseif ($connection instanceof \RedisCluster) { $connection->setOption( \RedisCluster::OPT_SERIALIZER, $config['serializer'] ?? \RedisCluster::SERIALIZER_IGBINARY ); if (count($this->servers) > 1) { $connection->setOption( \RedisCluster::OPT_SLAVE_FAILOVER, $config['failover'] ?? \RedisCluster::FAILOVER_NONE ); } } } public function createConnection() { $config = $this->getConfig(); if (!$this->servers) { throw new NotSupportedException('Empty server list to redis connection.'); } if (count($this->servers) === 1) { ['host' => $host, 'port' => $port] = $this->servers[0]; $connection = new \Redis(); $result = $connection->pconnect($host, $port); } else { $connections = []; foreach ($this->servers as $server) { $connections[] = $server['host'] . ':' . $server['port']; } $connection = new \RedisCluster( null, $connections, $config['timeout'] ?? null, $config['readTimeout'] ?? null, $config['persistent'] ?? true ); $result = true; } if ($result) { $this->configureConnection($connection); } else { $error = error_get_last(); if (isset($error["type"]) && $error["type"] === E_WARNING) { $exception = new \ErrorException($error['message'], 0, $error['type'], $error['file'], $error['line']); $application = Application::getInstance(); $exceptionHandler = $application->getExceptionHandler(); $exceptionHandler->writeToLog($exception); } } return $result? $connection : null; } }