• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/lib/data/configurator/redisconnectionconfigurator.php
  • Класс: BitrixMainDataConfiguratorRedisConnectionConfigurator
  • Вызов: RedisConnectionConfigurator::createConnection
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();

		if ($config['persistent'])
		{
			$result = $connection->pconnect($host, $port);
		}
		else
		{
			$result = $connection->connect($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;
}