mirror of
https://github.com/predis/predis.git
synced 2026-09-07 08:58:33 +00:00
Fix incorrect usage of instance method in static method.
We also added a test to check that the socket-based connection backend throws an exception when unable to resolve hostnames.
This commit is contained in:
@@ -229,7 +229,7 @@ class PhpiredisSocketConnection extends AbstractConnection
|
|||||||
* @param ParametersInterface $parameters Parameters used to initialize the connection.
|
* @param ParametersInterface $parameters Parameters used to initialize the connection.
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
private static function getAddress(ParametersInterface $parameters)
|
protected static function getAddress(ParametersInterface $parameters)
|
||||||
{
|
{
|
||||||
if ($parameters->scheme === 'unix') {
|
if ($parameters->scheme === 'unix') {
|
||||||
return $parameters->path;
|
return $parameters->path;
|
||||||
@@ -238,8 +238,8 @@ class PhpiredisSocketConnection extends AbstractConnection
|
|||||||
$host = $parameters->host;
|
$host = $parameters->host;
|
||||||
|
|
||||||
if (ip2long($host) === false) {
|
if (ip2long($host) === false) {
|
||||||
if (($addresses = gethostbynamel($host)) === false) {
|
if (false === $addresses = gethostbynamel($host)) {
|
||||||
$this->onConnectionError("Cannot resolve the address of '$host'.");
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $addresses[array_rand($addresses)];
|
return $addresses[array_rand($addresses)];
|
||||||
@@ -256,7 +256,10 @@ class PhpiredisSocketConnection extends AbstractConnection
|
|||||||
*/
|
*/
|
||||||
private function connectWithTimeout(ParametersInterface $parameters)
|
private function connectWithTimeout(ParametersInterface $parameters)
|
||||||
{
|
{
|
||||||
$host = self::getAddress($parameters);
|
if (false === $host = self::getAddress($parameters)) {
|
||||||
|
$this->onConnectionError("Cannot resolve the address of '$parameters->host'.");
|
||||||
|
}
|
||||||
|
|
||||||
$socket = $this->getResource();
|
$socket = $this->getResource();
|
||||||
|
|
||||||
socket_set_nonblock($socket);
|
socket_set_nonblock($socket);
|
||||||
|
|||||||
@@ -86,6 +86,18 @@ class PhpiredisSocketConnectionTest extends PredisConnectionTestCase
|
|||||||
$this->assertSame(array('foo', 'hoge', 'lol'), $connection->executeCommand($cmdLrange));
|
$this->assertSame(array('foo', 'hoge', 'lol'), $connection->executeCommand($cmdLrange));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group connected
|
||||||
|
* @expectedException Predis\Connection\ConnectionException
|
||||||
|
* @expectedExceptionMessage Cannot resolve the address of 'bogus.tld'.
|
||||||
|
*/
|
||||||
|
public function testThrowsExceptionOnUnresolvableHostname()
|
||||||
|
{
|
||||||
|
$parameters = $this->getParameters(array('host' => 'bogus.tld'));
|
||||||
|
$connection = new PhpiredisSocketConnection($parameters);
|
||||||
|
$connection->connect();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @group connected
|
* @group connected
|
||||||
* @expectedException Predis\Protocol\ProtocolException
|
* @expectedException Predis\Protocol\ProtocolException
|
||||||
|
|||||||
Reference in New Issue
Block a user