Пример #1
0
 /**
  * @group disconnected
  */
 public function testConnectionIsCluster()
 {
     $single = $this->getMock('Predis\\Network\\IConnectionSingle');
     $cluster = $this->getMock('Predis\\Network\\IConnectionCluster');
     $this->assertFalse(Helpers::isCluster($single));
     $this->assertTrue(Helpers::isCluster($cluster));
 }
Пример #2
0
 /**
  * Checks if the passed client instance satisfies the required conditions
  * needed to initialize a Publish / Subscribe context.
  *
  * @param Client Client instance used by the context.
  */
 private function checkCapabilities(Client $client)
 {
     if (Helpers::isCluster($client->getConnection())) {
         throw new NotSupportedException('Cannot initialize a PUB/SUB context over a cluster of connections');
     }
     $commands = array('publish', 'subscribe', 'unsubscribe', 'psubscribe', 'punsubscribe');
     if ($client->getProfile()->supportsCommands($commands) === false) {
         throw new NotSupportedException('The current profile does not support PUB/SUB related commands');
     }
 }
Пример #3
0
 /**
  * Returns a pipeline executor depending on the kind of the underlying
  * connection and the passed options.
  *
  * @param Client Client instance used by the context.
  * @param array Options for the context initialization.
  * @return IPipelineExecutor
  */
 protected function createExecutor(Client $client, array $options)
 {
     if (!$options) {
         return new StandardExecutor();
     }
     if (isset($options['executor'])) {
         $executor = $options['executor'];
         if (!$executor instanceof IPipelineExecutor) {
             throw new \InvalidArgumentException('The executor option accepts only instances ' . 'of Predis\\Pipeline\\IPipelineExecutor');
         }
         return $executor;
     }
     if (isset($options['safe']) && $options['safe'] == true) {
         $isCluster = Helpers::isCluster($client->getConnection());
         return $isCluster ? new SafeClusterExecutor() : new SafeExecutor();
     }
     return new StandardExecutor();
 }
Пример #4
0
 /**
  * Checks if the passed client instance satisfies the required conditions
  * needed to initialize a transaction context.
  *
  * @param Client Client instance used by the context.
  */
 private function checkCapabilities(Client $client)
 {
     if (Helpers::isCluster($client->getConnection())) {
         throw new NotSupportedException('Cannot initialize a MULTI/EXEC context over a cluster of connections');
     }
     $profile = $client->getProfile();
     if ($profile->supportsCommands(array('multi', 'exec', 'discard')) === false) {
         throw new NotSupportedException('The current profile does not support MULTI, EXEC and DISCARD');
     }
     $this->canWatch = $profile->supportsCommands(array('watch', 'unwatch'));
 }
Пример #5
0
 /**
  * Executes the specified Redis command on all the nodes of a cluster.
  *
  * @param ICommand $command A Redis command.
  * @return array
  */
 public function executeCommandOnShards(ICommand $command)
 {
     if (Helpers::isCluster($this->connection)) {
         $replies = array();
         foreach ($this->connection as $connection) {
             $replies[] = $connection->executeCommand($command);
         }
         return $replies;
     }
     return array($this->connection->executeCommand($command));
 }
Пример #6
0
 /**
  * Checks if the passed client instance satisfies the required conditions
  * needed to initialize a monitor context.
  *
  * @param Client Client instance used by the context.
  */
 private function checkCapabilities(Client $client)
 {
     if (Helpers::isCluster($client->getConnection())) {
         throw new ClientException('Cannot initialize a monitor context over a cluster of connections');
     }
     if ($client->getProfile()->supportsCommand('monitor') === false) {
         throw new ClientException('The current profile does not support the MONITOR command');
     }
 }