Skip to content

Commit 38fd27e

Browse files
committed
silence PHP warnings issued by Redis::connect()
1 parent da4eb8b commit 38fd27e

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/Symfony/Component/Messenger/Bridge/Redis/Transport/Connection.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,20 @@ private static function initializeRedis(\Redis $redis, string $host, int $port,
121121
return $redis;
122122
}
123123

124-
$redis->connect($host, $port);
124+
@$redis->connect($host, $port);
125+
126+
set_error_handler(function ($type, $msg) use (&$error) { $error = $msg; });
127+
128+
try {
129+
$isConnected = $redis->isConnected();
130+
} finally {
131+
restore_error_handler();
132+
}
133+
134+
if (!$isConnected) {
135+
throw new InvalidArgumentException(sprintf('Redis connection failed: %s', preg_match('/^Redis::p?connect\(\): (.*)/', $error ?? $redis->getLastError() ?? '', $matches) ? \sprintf(' (%s)', $matches[1]) : ''));
136+
}
137+
125138
$redis->setOption(\Redis::OPT_SERIALIZER, $serializer);
126139

127140
if (null !== $auth && !$redis->auth($auth)) {

0 commit comments

Comments
 (0)