Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6613d26

Browse filesBrowse files
committed
silence PHP warnings issued by Redis::connect()
1 parent da4eb8b commit 6613d26
Copy full SHA for 6613d26

File tree

1 file changed

+15
-1
lines changed
Filter options

1 file changed

+15
-1
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/Bridge/Redis/Transport/Connection.php
+15-1Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,21 @@ 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+
$error = null;
127+
set_error_handler(function ($type, $msg) use (&$error) { $error = $msg; });
128+
129+
try {
130+
$isConnected = $redis->isConnected();
131+
} finally {
132+
restore_error_handler();
133+
}
134+
135+
if (!$isConnected) {
136+
throw new InvalidArgumentException(sprintf('Redis connection failed: %s', preg_match('/^Redis::p?connect\(\): (.*)/', $error ?? $redis->getLastError() ?? '', $matches) ? \sprintf(' (%s)', $matches[1]) : ''));
137+
}
138+
125139
$redis->setOption(\Redis::OPT_SERIALIZER, $serializer);
126140

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

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.