62 if ($connection instanceof \Redis)
64 $connection->setOption(\Redis::OPT_SERIALIZER,
$config[
'serializer'] ?? \Redis::SERIALIZER_IGBINARY);
66 elseif ($connection instanceof \RedisCluster)
68 $connection->setOption(
69 \RedisCluster::OPT_SERIALIZER,
70 $config[
'serializer'] ?? \RedisCluster::SERIALIZER_IGBINARY
73 if (count($this->servers) > 1)
75 $connection->setOption(
76 \RedisCluster::OPT_SLAVE_FAILOVER,
77 $config[
'failover'] ?? \RedisCluster::FAILOVER_NONE
91 if (count($this->servers) === 1)
93 [
'host' => $host,
'port' => $port] = $this->servers[0];
94 $connection = new \Redis();
98 $result = $connection->pconnect($host, $port);
102 $result = $connection->connect($host, $port);
108 foreach ($this->servers as $server)
110 $connections[] = $server[
'host'] .
':' . $server[
'port'];
113 $connection = new \RedisCluster(
117 $config[
'readTimeout'] ??
null,
129 $error = error_get_last();
130 if (isset($error[
"type"]) && $error[
"type"] === E_WARNING)
132 $exception = new \ErrorException($error[
'message'], 0, $error[
'type'], $error[
'file'], $error[
'line']);
134 $exceptionHandler = $application->getExceptionHandler();
135 $exceptionHandler->writeToLog($exception);
139 return $result? $connection :
null;