/** * {@inheritdoc} */ public function handle(CompositeConnectionInterface $connection, $payload) { $length = (int) $payload; if ("{$length}" !== $payload) { CommunicationException::handle(new ProtocolException($connection, "Cannot parse '{$payload}' as a valid length for a bulk response [{$connection->getParameters()}]")); } if ($length >= 0) { return substr($connection->readBuffer($length + 2), 0, -2); } if ($length == -1) { return; } CommunicationException::handle(new ProtocolException($connection, "Value '{$payload}' is not a valid length for a bulk response [{$connection->getParameters()}]")); return; }
/** * {@inheritdoc} */ public function handle(CompositeConnectionInterface $connection, $payload) { $length = (int) $payload; if ("{$length}" !== $payload) { CommunicationException::handle(new ProtocolException($connection, "Cannot parse '{$payload}' as a valid length of a multi-bulk response [{$connection->getParameters()}]")); } if ($length === -1) { return; } $list = array(); if ($length > 0) { $handlersCache = array(); $reader = $connection->getProtocol()->getResponseReader(); for ($i = 0; $i < $length; ++$i) { $header = $connection->readLine(); $prefix = $header[0]; if (isset($handlersCache[$prefix])) { $handler = $handlersCache[$prefix]; } else { $handler = $reader->getHandler($prefix); $handlersCache[$prefix] = $handler; } $list[$i] = $handler->handle($connection, substr($header, 1)); } } return $list; }
/** * {@inheritdoc} */ public function handle(CompositeConnectionInterface $connection, $payload) { $length = (int) $payload; if ("{$length}" != $payload) { CommunicationException::handle(new ProtocolException($connection, "Cannot parse '{$payload}' as a valid length for a multi-bulk response [{$connection->getParameters()}]")); } return new MultiBulkIterator($connection, $length); }
/** * {@inheritdoc} */ public function handle(CompositeConnectionInterface $connection, $payload) { if (is_numeric($payload)) { $integer = (int) $payload; return $integer == $payload ? $integer : $payload; } if ($payload !== 'nil') { CommunicationException::handle(new ProtocolException($connection, "Cannot parse '{$payload}' as a valid numeric response [{$connection->getParameters()}]")); } return; }
/** * Handles protocol errors generated while reading responses from a * connection. * * @param CompositeConnectionInterface $connection Redis connection that generated the error. * @param string $message Error message. */ protected function onProtocolError(CompositeConnectionInterface $connection, $message) { CommunicationException::handle(new ProtocolException($connection, "{$message} [{$connection->getParameters()}]")); }