bug #39434 [Cache] Bugfix provide the correct host and port when throwing the exception (renan)
This PR was merged into the 5.3-dev branch.
Discussion
----------
[Cache] Bugfix provide the correct host and port when throwing the exception
| Q | A
| ------------- | ---
| Branch? | 5.x
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Tickets | none
| License | MIT
| Doc PR | none
The message before was including the result of the `getMasterAddrByName` call of which ended with:
```
Failed to retrieve master information from master name "mymaster" and address ":0".
```
Commits
-------
276bbb5e85
[Cache] Bugfix provide the correct host and port when throwing the exception
This commit is contained in:
commit
f66b853f4a
@ -41,4 +41,13 @@ class RedisAdapterSentinelTest extends AbstractRedisAdapterTest
|
||||
$dsn = 'redis:?host[redis1]&host[redis2]&host[redis3]&redis_cluster=1&redis_sentinel=mymaster';
|
||||
RedisAdapter::createConnection($dsn);
|
||||
}
|
||||
|
||||
public function testExceptionMessageWhenFailingToRetrieveMasterInformation()
|
||||
{
|
||||
$hosts = getenv('REDIS_SENTINEL_HOSTS');
|
||||
$firstHost = explode(' ', $hosts)[0];
|
||||
$this->expectException('Symfony\Component\Cache\Exception\InvalidArgumentException');
|
||||
$this->expectExceptionMessage('Failed to retrieve master information from master name "invalid-masterset-name" and address "'.$firstHost.'".');
|
||||
AbstractAdapter::createConnection('redis:?host['.str_replace(' ', ']&host[', $hosts).']', ['redis_sentinel' => 'invalid-masterset-name']);
|
||||
}
|
||||
}
|
||||
|
@ -186,9 +186,11 @@ trait RedisTrait
|
||||
if (isset($params['redis_sentinel'])) {
|
||||
$sentinel = new \RedisSentinel($host, $port, $params['timeout'], (string) $params['persistent_id'], $params['retry_interval'], $params['read_timeout']);
|
||||
|
||||
if (![$host, $port] = $sentinel->getMasterAddrByName($params['redis_sentinel'])) {
|
||||
if (!$address = $sentinel->getMasterAddrByName($params['redis_sentinel'])) {
|
||||
throw new InvalidArgumentException(sprintf('Failed to retrieve master information from master name "%s" and address "%s:%d".', $params['redis_sentinel'], $host, $port));
|
||||
}
|
||||
|
||||
[$host, $port] = $address;
|
||||
}
|
||||
|
||||
try {
|
||||
|
Reference in New Issue
Block a user