diff --git a/lib/Predis.php b/lib/Predis.php index aada55fe..a70c91f0 100644 --- a/lib/Predis.php +++ b/lib/Predis.php @@ -322,24 +322,24 @@ class ResponseBulkHandler implements IResponseHandler { if ($dataLength > 0) { $value = $connection->readBytes($dataLength); - if ($connection->readBytes(2) !== ResponseReader::NEWLINE) { - Utilities\Shared::onCommunicationException(new MalformedServerResponse( - $connection, 'Did not receive a new-line at the end of a bulk response' - )); - } + self::discardNewLine($connection); return $value; } else if ($dataLength == 0) { - if ($connection->readBytes(2) !== ResponseReader::NEWLINE) { - Utilities\Shared::onCommunicationException(new MalformedServerResponse( - $connection, 'Did not receive a new-line at the end of a bulk response' - )); - } + self::discardNewLine($connection); return ''; } return null; } + + private static function discardNewLine(Connection $connection) { + if ($connection->readBytes(2) !== ResponseReader::NEWLINE) { + Utilities\Shared::onCommunicationException(new MalformedServerResponse( + $connection, 'Did not receive a new-line at the end of a bulk response' + )); + } + } } class ResponseMultiBulkHandler implements IResponseHandler {