/** * Execute a Riak command * * @param Command $command * @return Command\Response * @throws Exception */ public function execute(Command $command) { $response = $this->getActiveNode()->execute($command, $this->api); // if more than 1 node configured, lets try a different node up to max connection attempts if (empty($response) && count($this->nodes) > 1 && $this->attempts < $this->getConfigValue('max_connect_attempts')) { $response = $this->pickNewNode()->execute($command); } elseif (empty($response) && $this->attempts >= $this->getConfigValue('max_connect_attempts')) { throw new Exception('Nodes unreachable. Error Msg: ' . $this->api->getError()); } elseif ($response == false) { throw new Exception('Command failed to execute against Riak. Error Msg: ' . $this->api->getError()); } return $response; }
/** * @param Command $command * @param Api $api * * @return Command\Response * @throws Exception */ public function execute(Command $command, Api $api) { $success = $api->prepare($command, $this)->send(); if ($success === FALSE) { throw new Exception('Command failed to execute against Riak. Error Msg: ' . $api->getError()); } $command->setResponse($api->getStatusCode(), $api->getResponseHeaders(), $api->getResponseBody()); return $command->getResponse(); }