mirror of
https://github.com/predis/predis.git
synced 2026-08-30 12:15:03 +00:00
Remove useless helpers.
This commit is contained in:
@@ -14,6 +14,7 @@ namespace Predis;
|
||||
use Predis\Command\CommandInterface;
|
||||
use Predis\Option\ClientOptionsInterface;
|
||||
use Predis\Connection\ConnectionInterface;
|
||||
use Predis\Connection\AggregatedConnectionInterface;
|
||||
use Predis\Profile\ServerProfileInterface;
|
||||
use Predis\Option\ClientOptions;
|
||||
use Predis\Profile\ServerProfile;
|
||||
@@ -187,9 +188,10 @@ class Client implements ClientInterface
|
||||
public function getConnection($id = null)
|
||||
{
|
||||
if (isset($id)) {
|
||||
if (!Helpers::isAggregated($this->connection)) {
|
||||
$message = 'Retrieving connections by alias is supported only with aggregated connections (cluster or replication)';
|
||||
throw new NotSupportedException($message);
|
||||
if (!$this->connection instanceof AggregatedConnectionInterface) {
|
||||
throw new NotSupportedException(
|
||||
'Retrieving connections by alias is supported only with aggregated connections (cluster or replication)'
|
||||
);
|
||||
}
|
||||
return $this->connection->getConnectionById($id);
|
||||
}
|
||||
|
||||
@@ -22,28 +22,6 @@ use Predis\Connection\AggregatedConnectionInterface;
|
||||
*/
|
||||
class Helpers
|
||||
{
|
||||
/**
|
||||
* Checks if the specified connection represents an aggregation of connections.
|
||||
*
|
||||
* @param ConnectionInterface $connection Connection object.
|
||||
* @return Boolean
|
||||
*/
|
||||
public static function isAggregated(ConnectionInterface $connection)
|
||||
{
|
||||
return $connection instanceof AggregatedConnectionInterface;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the specified connection represents a cluster.
|
||||
*
|
||||
* @param ConnectionInterface $connection Connection object.
|
||||
* @return Boolean
|
||||
*/
|
||||
public static function isCluster(ConnectionInterface $connection)
|
||||
{
|
||||
return $connection instanceof ClusterConnectionInterface;
|
||||
}
|
||||
|
||||
/**
|
||||
* Offers a generic and reusable method to handle exceptions generated by
|
||||
* a connection object.
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
namespace Predis\Monitor;
|
||||
|
||||
use Predis\ClientInterface;
|
||||
use Predis\Helpers;
|
||||
use Predis\NotSupportedException;
|
||||
use Predis\Connection\AggregatedConnectionInterface;
|
||||
|
||||
/**
|
||||
* Client-side abstraction of a Redis MONITOR context.
|
||||
@@ -52,7 +52,7 @@ class MonitorContext implements \Iterator
|
||||
*/
|
||||
private function checkCapabilities(ClientInterface $client)
|
||||
{
|
||||
if (Helpers::isCluster($client->getConnection())) {
|
||||
if ($client->getConnection() instanceof AggregatedConnectionInterface) {
|
||||
throw new NotSupportedException('Cannot initialize a monitor context over a cluster of connections');
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ use Predis\ClientInterface;
|
||||
use Predis\Helpers;
|
||||
use Predis\ClientException;
|
||||
use Predis\NotSupportedException;
|
||||
use Predis\Connection\AggregatedConnectionInterface;
|
||||
|
||||
/**
|
||||
* Client-side abstraction of a Publish / Subscribe context.
|
||||
@@ -48,7 +49,7 @@ class PubSubContext extends AbstractPubSubContext
|
||||
*/
|
||||
private function checkCapabilities(ClientInterface $client)
|
||||
{
|
||||
if (Helpers::isCluster($client->getConnection())) {
|
||||
if ($client->getConnection() instanceof AggregatedConnectionInterface) {
|
||||
throw new NotSupportedException('Cannot initialize a PUB/SUB context over a cluster of connections');
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ use Predis\BasicClientInterface;
|
||||
use Predis\ExecutableContextInterface;
|
||||
use Predis\ResponseErrorInterface;
|
||||
use Predis\Command\CommandInterface;
|
||||
use Predis\Helpers;
|
||||
use Predis\Connection\AggregatedConnectionInterface;
|
||||
use Predis\ResponseQueued;
|
||||
use Predis\ClientException;
|
||||
use Predis\ServerException;
|
||||
@@ -32,12 +32,12 @@ use Predis\Protocol\ProtocolException;
|
||||
*/
|
||||
class MultiExecContext implements BasicClientInterface, ExecutableContextInterface
|
||||
{
|
||||
const STATE_RESET = 0; // 0b00000
|
||||
const STATE_INITIALIZED = 1; // 0b00001
|
||||
const STATE_INSIDEBLOCK = 2; // 0b00010
|
||||
const STATE_DISCARDED = 4; // 0b00100
|
||||
const STATE_CAS = 8; // 0b01000
|
||||
const STATE_WATCH = 16; // 0b10000
|
||||
const STATE_RESET = 0; // 0b00000
|
||||
const STATE_INITIALIZED = 1; // 0b00001
|
||||
const STATE_INSIDEBLOCK = 2; // 0b00010
|
||||
const STATE_DISCARDED = 4; // 0b00100
|
||||
const STATE_CAS = 8; // 0b01000
|
||||
const STATE_WATCH = 16; // 0b10000
|
||||
|
||||
private $state;
|
||||
private $canWatch;
|
||||
@@ -117,7 +117,7 @@ class MultiExecContext implements BasicClientInterface, ExecutableContextInterfa
|
||||
*/
|
||||
private function checkCapabilities(ClientInterface $client)
|
||||
{
|
||||
if (Helpers::isCluster($client->getConnection())) {
|
||||
if ($client->getConnection() instanceof AggregatedConnectionInterface) {
|
||||
throw new NotSupportedException('Cannot initialize a MULTI/EXEC context over a cluster of connections');
|
||||
}
|
||||
|
||||
|
||||
@@ -18,18 +18,6 @@ use \PHPUnit_Framework_TestCase as StandardTestCase;
|
||||
*/
|
||||
class HelpersTest extends StandardTestCase
|
||||
{
|
||||
/**
|
||||
* @group disconnected
|
||||
*/
|
||||
public function testConnectionIsCluster()
|
||||
{
|
||||
$single = $this->getMock('Predis\Connection\SingleConnectionInterface');
|
||||
$cluster = $this->getMock('Predis\Connection\ClusterConnectionInterface');
|
||||
|
||||
$this->assertFalse(Helpers::isCluster($single));
|
||||
$this->assertTrue(Helpers::isCluster($cluster));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group disconnected
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user