Exemplo n.º 1
0
 /**
  * @inheritdoc
  */
 public function execute(CommandInterface $command)
 {
     if (!$this->isConnected()) {
         throw new ConnectionException('No connection established');
     }
     return $this->client->executeRaw(array_merge([$command->getCommand()], $command->getArguments()));
 }
Exemplo n.º 2
0
 /**
  * @inheritdoc
  */
 public function execute(CommandInterface $command)
 {
     $commandName = $command->getCommand();
     $arguments = $command->getArguments();
     $totalArguments = count($arguments);
     $parts = ['*' . ($totalArguments + 1), '$' . strlen($commandName), $commandName];
     for ($i = 0; $i < $totalArguments; $i++) {
         $argument = $arguments[$i];
         $parts[] = '$' . strlen($argument);
         $parts[] = $argument;
     }
     $this->send(implode("\r\n", $parts) . "\r\n");
     return $this->receive($command->isBlocking());
 }
Exemplo n.º 3
0
 /**
  * Register a command handler
  *
  * @param CommandInterface $commandHandler Command
  * @return void
  */
 public function registerCommand(CommandInterface $commandHandler)
 {
     $command = strtoupper($commandHandler->getCommand());
     $this->commandHandlers[$command] = $commandHandler;
 }
Exemplo n.º 4
0
 /**
  * Postprocess the command execution, eg. update node stats
  *
  * @param CommandInterface $command
  * @param mixed            $response
  *
  * @return mixed
  * @throws ConnectionException
  */
 protected function postprocessExecution(CommandInterface $command, $response)
 {
     if ($command instanceof GetJob) {
         $this->updateNodeStats($command->parse($response));
         $this->switchNodeIfNeeded();
     }
     return $response;
 }