diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f2455e..e253ce5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## CHANGELOG +### v1.6.1 (2017-02-04) +- Added check for empty data on reading response. +- Fixed some tests. + ### v1.6.0 (2017-01-07) - Added support for Redis 4.0 (the Client was tested with Redis 4.0 RC2). - Added support for Redis Cluster. diff --git a/README.md b/README.md index 8a09856..d5cb3fe 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ [![MIT license](http://img.shields.io/badge/license-MIT-brightgreen.svg)](http://opensource.org/licenses/MIT) [![Latest Stable Version](https://poser.pugx.org/cheprasov/php-redis-client/v/stable)](https://packagist.org/packages/cheprasov/php-redis-client) [![Total Downloads](https://poser.pugx.org/cheprasov/php-redis-client/downloads)](https://packagist.org/packages/cheprasov/php-redis-client) -# RedisClient v1.6.0 for PHP >= 5.5 +# RedisClient v1.6.1 for PHP >= 5.5 ## About RedisClient is a fast, fully-functional and user-friendly client for Redis, optimized for performance. RedisClient supports the latest versions of Redis starting from __2.6__ to __4.0__ @@ -16,7 +16,7 @@ RedisClient is a fast, fully-functional and user-friendly client for Redis, opti - Connections to Redis are established lazily by the client upon the first command. - Easy to use with IDE, client has PHPDocs for all supported versions. - By default, the client works with the latest stable version of Redis (3.2). -- Client was tested on the next versions of Redis: 2.6.17, 2.8.24, 3.0.7, 3.2.6, 4.0 RC2 (and other). +- Client was tested on the next versions of Redis: 2.6.17, 2.8.24, 3.0.7, 3.2.7, 4.0 RC2 (and other). - Also, Client was tested on PHP 5.5, 5.6, 7.0, 7.1, HHVM. ## Usage diff --git a/composer.json b/composer.json index ff52478..13fbb93 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "cheprasov/php-redis-client", - "version": "1.6.0", + "version": "1.6.1", "description": "Php client for Redis. It is a fast, fully-functional and user-friendly client for Redis, optimized for performance. RedisClient supports the latest versions of Redis starting from 2.6 to 4.0", "homepage": "http://github.com/cheprasov/php-redis-client", "minimum-stability": "stable", diff --git a/src/RedisClient/Client/AbstractRedisClient.php b/src/RedisClient/Client/AbstractRedisClient.php index 613b4f2..623fea5 100644 --- a/src/RedisClient/Client/AbstractRedisClient.php +++ b/src/RedisClient/Client/AbstractRedisClient.php @@ -26,7 +26,7 @@ abstract class AbstractRedisClient { - const VERSION = '1.6.0'; + const VERSION = '1.6.1'; const CONFIG_SERVER = 'server'; const CONFIG_TIMEOUT = 'timeout'; diff --git a/src/RedisClient/Command/Parameter/Parameter.php b/src/RedisClient/Command/Parameter/Parameter.php index 6babc99..77d55dc 100644 --- a/src/RedisClient/Command/Parameter/Parameter.php +++ b/src/RedisClient/Command/Parameter/Parameter.php @@ -91,7 +91,7 @@ public static function assocArrayFlip(array $array) { /** * @param string $operation * @return string - * @return InvalidArgumentException + * @throws InvalidArgumentException */ public static function bitOperation($operation) { $operation = strtoupper((string)$operation); @@ -134,7 +134,7 @@ public static function enum($param, array $enum) { * @return float */ public static function float($float) { - return (float) $float; + return (float)$float; } /** @@ -145,7 +145,8 @@ public static function float($float) { /** * @param string $unit - * @return string mixed + * @return string + * @throws InvalidArgumentException */ public static function geoUnit($unit) { if (!in_array($unit, static::$geoUnits)) { @@ -193,6 +194,7 @@ public static function keys($keys) { /** * @param int|string|int[]|string[] $limit * @return int[] + * @throws InvalidArgumentException */ public static function limit($limit) { if (is_numeric($limit)) { @@ -200,7 +202,7 @@ public static function limit($limit) { } if (is_array($limit) && isset($limit['count'])) { return [ - empty($limit['offset']) ? 0: (int) $limit['offset'], + empty($limit['offset']) ? 0: (int)$limit['offset'], (int)$limit['count'], ]; } @@ -223,6 +225,7 @@ public static function limit($limit) { /** * @param int|string $param * @return int|string + * @throws InvalidArgumentException */ public static function minMax($param) { $param = trim($param); @@ -235,6 +238,7 @@ public static function minMax($param) { /** * @param string $param * @return string + * @throws InvalidArgumentException */ public static function nxXx($param) { if ($param === 'NX' || $param === 'XX') { @@ -253,6 +257,7 @@ public static function nxXx($param) { /** * @param int|float|string $int * @return int + * @throws InvalidArgumentException */ public static function port($int) { $int = (int)$int; @@ -267,6 +272,7 @@ public static function port($int) { /** * @param string|int $param * @return string + * @throws InvalidArgumentException */ public static function specifyInterval($param) { $param = trim($param); diff --git a/src/RedisClient/Command/Response/ResponseParser.php b/src/RedisClient/Command/Response/ResponseParser.php index f8ca219..6d46a4c 100644 --- a/src/RedisClient/Command/Response/ResponseParser.php +++ b/src/RedisClient/Command/Response/ResponseParser.php @@ -105,7 +105,7 @@ public static function parseInfo($response) { if (!$response) { return $response; } - $response = trim((string) $response); + $response = trim((string)$response); $result = []; $link = &$result; foreach (explode("\n", $response) as $line) { diff --git a/src/RedisClient/Connection/StreamConnection.php b/src/RedisClient/Connection/StreamConnection.php index 7659e55..b45f2d6 100644 --- a/src/RedisClient/Connection/StreamConnection.php +++ b/src/RedisClient/Connection/StreamConnection.php @@ -122,14 +122,18 @@ public function readLine() { /** * @param int $length - * @return string + * @return string|null */ public function read($length) { $resource = $this->getResource(); $left = $length; $data = ''; do { - $data .= fread($resource, min($left, 8192)); + $read = fread($resource, min($left, 8192)); + if (false === $read) { + return null; + } + $data .= $read; $left = $length - strlen($data); } while ($left > 0); diff --git a/src/RedisClient/Protocol/RedisProtocol.php b/src/RedisClient/Protocol/RedisProtocol.php index 83ed9bb..07d269f 100644 --- a/src/RedisClient/Protocol/RedisProtocol.php +++ b/src/RedisClient/Protocol/RedisProtocol.php @@ -58,7 +58,7 @@ public function getConnection() { */ protected function pack($data) { if (is_string($data) || is_int($data) || is_bool($data) || is_float($data) || is_null($data)) { - return $this->packProtocolBulkString((string) $data); + return $this->packProtocolBulkString((string)$data); } if (is_array($data)) { return $this->packProtocolArray($data); @@ -119,7 +119,11 @@ protected function read() { if ($length === -1) { return null; } - return substr($this->Connection->read($length + 2), 0, -2); + $read = $this->Connection->read($length + 2); + if (is_null($read)) { + throw new EmptyResponseException('Can not read response. Please, check connection timeout.'); + } + return substr($read, 0, -2); } if ($type === self::TYPE_SIMPLE_STRINGS) { @@ -130,7 +134,7 @@ protected function read() { } if ($type === self::TYPE_INTEGERS) { - return (int) $data; + return (int)$data; } if ($type === self::TYPE_ARRAYS) { diff --git a/tests/Integration/Version3x2/ServerCommandsTest.php b/tests/Integration/Version3x2/ServerCommandsTest.php index 8df3fd3..ed1a7d0 100644 --- a/tests/Integration/Version3x2/ServerCommandsTest.php +++ b/tests/Integration/Version3x2/ServerCommandsTest.php @@ -22,7 +22,7 @@ class ServerCommandsTest extends \Test\Integration\Version3x0\ServerCommandsTest */ public function test_commandCount() { $Redis = static::$Redis; - $this->assertSame(172, $Redis->commandCount()); + $this->assertSame(174, $Redis->commandCount()); } /** @@ -49,9 +49,11 @@ public function test_command() { 'debug', 'echo', 'eval', + 'host:', 'latency', 'pfdebug', 'pfselftest', + 'post', 'psync', 'replconf', 'restore-asking',