/** * @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())); }
/** * @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()); }
/** * Register a command handler * * @param CommandInterface $commandHandler Command * @return void */ public function registerCommand(CommandInterface $commandHandler) { $command = strtoupper($commandHandler->getCommand()); $this->commandHandlers[$command] = $commandHandler; }
/** * 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; }