Skip to content

Commit

Permalink
Merge pull request #52 from cheprasov/v161
Browse files Browse the repository at this point in the history
v161
  • Loading branch information
cheprasov authored Feb 4, 2017
2 parents bd07732 + 6818bc7 commit 4887f50
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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__
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/RedisClient/Client/AbstractRedisClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
14 changes: 10 additions & 4 deletions src/RedisClient/Command/Parameter/Parameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -134,7 +134,7 @@ public static function enum($param, array $enum) {
* @return float
*/
public static function float($float) {
return (float) $float;
return (float)$float;
}

/**
Expand All @@ -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)) {
Expand Down Expand Up @@ -193,14 +194,15 @@ public static function keys($keys) {
/**
* @param int|string|int[]|string[] $limit
* @return int[]
* @throws InvalidArgumentException
*/
public static function limit($limit) {
if (is_numeric($limit)) {
return [0, (int)$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'],
];
}
Expand All @@ -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);
Expand All @@ -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') {
Expand All @@ -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;
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/RedisClient/Command/Response/ResponseParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 6 additions & 2 deletions src/RedisClient/Connection/StreamConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
10 changes: 7 additions & 3 deletions src/RedisClient/Protocol/RedisProtocol.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand All @@ -130,7 +134,7 @@ protected function read() {
}

if ($type === self::TYPE_INTEGERS) {
return (int) $data;
return (int)$data;
}

if ($type === self::TYPE_ARRAYS) {
Expand Down
4 changes: 3 additions & 1 deletion tests/Integration/Version3x2/ServerCommandsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

/**
Expand All @@ -49,9 +49,11 @@ public function test_command() {
'debug',
'echo',
'eval',
'host:',
'latency',
'pfdebug',
'pfselftest',
'post',
'psync',
'replconf',
'restore-asking',
Expand Down

0 comments on commit 4887f50

Please sign in to comment.