Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## CHANGELOG

### v1.2.3 (2016-05-02)
- Fixed command **PING** for Redis <= 2.6.
- Added common tests.

### v1.2.2 (2016-03-30)
- Fixed annotations and phpDocs.
- Fixed some tests.
Expand Down
3 changes: 2 additions & 1 deletion 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.2.2 for PHP >= 5.5
# RedisClient v1.2.3 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 __3.2.0-RC3__
Expand All @@ -15,6 +15,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.
- About **6.5-8.5% faster** than predis (based on this test: https://github.com/cheprasov/php-redis-client-vs-predis-test)

## 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.2.2",
"version": "1.2.3",
"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 3.2.0-RC3",
"homepage": "http://github.com/cheprasov/php-redis-client",
"minimum-stability": "stable",
Expand Down
3 changes: 2 additions & 1 deletion src/RedisClient/Client/AbstractRedisClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

abstract class AbstractRedisClient {

const VERSION = '1.2.2';
const VERSION = '1.2.3';

const CONFIG_SERVER = 'server';
const CONFIG_TIMEOUT = 'timeout';
Expand Down Expand Up @@ -184,6 +184,7 @@ public function executeRaw($structure) {
}

/**
* Command will parsed by the client, before sent to server
* @param string $command
* @return mixed
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,14 @@ public function echoMessage($message) {
}

/**
* PING [message]
* PING
* Available since 1.0.0.
* @link http://redis.io/commands/ping
*
* @param string $message
* @return string Returns message
*/
public function ping($message = null) {
return $this->returnCommand(['PING'], isset($message) ? [$message] : null);
public function ping() {
return $this->returnCommand(['PING']);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
namespace RedisClient\Command\Traits\Version2x8;

use RedisClient\Command\Traits\AbstractCommandsTrait;
use RedisClient\Command\Traits\Version2x6\ConnectionCommandsTrait;
use RedisClient\Command\Traits\Version2x6\ListsCommandsTrait;
use RedisClient\Command\Traits\Version2x6\ScriptingCommandsTrait;
use RedisClient\Command\Traits\Version2x6\TransactionsCommandsTrait;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* This file is part of RedisClient.
* git: https://github.com/cheprasov/php-redis-client
*
* (C) Alexander Cheprasov <cheprasov.84@ya.ru>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace RedisClient\Command\Traits\Version2x8;

use RedisClient\Command\Traits\Version2x6\ConnectionCommandsTrait as ConnectionCommandsTraitVersion2x6;

/**
* Connection Commands
* @link http://redis.io/commands#connection
*
* @method string echo($message)
*/
trait ConnectionCommandsTrait {

use ConnectionCommandsTraitVersion2x6;

/**
* PING [message]
* Available since 1.0.0.
* @link http://redis.io/commands/ping
*
* @param string $message
* @return string Returns message
*/
public function ping($message = null) {
return $this->returnCommand(['PING'], isset($message) ? [$message] : null);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace RedisClient\Command\Traits\Version3x0;

use RedisClient\Command\Traits\AbstractCommandsTrait;
use RedisClient\Command\Traits\Version2x6\ConnectionCommandsTrait;
use RedisClient\Command\Traits\Version2x8\ConnectionCommandsTrait;
use RedisClient\Command\Traits\Version2x8\HashesCommandsTrait;
use RedisClient\Command\Traits\Version2x6\ListsCommandsTrait;
use RedisClient\Command\Traits\Version2x6\ScriptingCommandsTrait;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use RedisClient\Command\Traits\Version2x8\LatencyCommandsTrait;
use RedisClient\Command\Traits\Version2x8\PubSubCommandsTrait;
use RedisClient\Command\Traits\Version3x0\ClusterCommandsTrait;
use RedisClient\Command\Traits\Version2x6\ConnectionCommandsTrait;
use RedisClient\Command\Traits\Version2x8\ConnectionCommandsTrait;
use RedisClient\Command\Traits\Version2x8\HyperLogLogCommandsTrait;
use RedisClient\Command\Traits\Version2x6\ListsCommandsTrait;
use RedisClient\Command\Traits\Version3x0\SortedSetsCommandsTrait;
Expand Down
2 changes: 1 addition & 1 deletion src/RedisClient/Pipeline/Version/Pipeline2x6.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* @method Pipeline2x6 auth($password)
* @method Pipeline2x6 echo($message)
* @method Pipeline2x6 echoMessage($message) - alias method for reversed word <echo>
* @method Pipeline2x6 ping($message = null)
* @method Pipeline2x6 ping()
* @method Pipeline2x6 quit()
* @method Pipeline2x6 select($db)
*
Expand Down
5 changes: 4 additions & 1 deletion src/RedisClient/Pipeline/Version/Pipeline2x8.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* @method Pipeline2x8 auth($password)
* @method Pipeline2x8 echo($message)
* @method Pipeline2x8 echoMessage($message) - alias method for reversed word <echo>
* @method Pipeline2x8 ping($message = null)
* -method Pipeline2x8 ping()
* @method Pipeline2x8 quit()
* @method Pipeline2x8 select($db)
*
Expand Down Expand Up @@ -186,6 +186,9 @@
*
* Redis version 2.8
*
* Connection
* @method Pipeline2x8 ping($message = null)
*
* Hashes
* @method Pipeline2x8 hscan($key, $cursor, $pattern = null, $count = null)
*
Expand Down
5 changes: 4 additions & 1 deletion src/RedisClient/Pipeline/Version/Pipeline3x0.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* @method Pipeline3x0 auth($password)
* @method Pipeline3x0 echo($message)
* @method Pipeline3x0 echoMessage($message) - alias method for reversed word <echo>
* @method Pipeline3x0 ping($message = null)
* -method Pipeline3x0 ping()
* @method Pipeline3x0 quit()
* @method Pipeline3x0 select($db)
*
Expand Down Expand Up @@ -186,6 +186,9 @@
*
* Redis version 2.8
*
* Connection
* @method Pipeline3x0 ping($message = null)
*
* Hashes
* @method Pipeline3x0 hscan($key, $cursor, $pattern = null, $count = null)
*
Expand Down
5 changes: 4 additions & 1 deletion src/RedisClient/Pipeline/Version/Pipeline3x2.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* @method Pipeline3x2 auth($password)
* @method Pipeline3x2 echo($message)
* @method Pipeline3x2 echoMessage($message) - alias method for reversed word <echo>
* @method Pipeline3x2 ping($message = null)
* -method Pipeline3x2 ping()
* @method Pipeline3x2 quit()
* @method Pipeline3x2 select($db)
*
Expand Down Expand Up @@ -186,6 +186,9 @@
*
* Redis version 2.8
*
* Connection
* @method Pipeline3x2 ping($message = null)
*
* Hashes
* @method Pipeline3x2 hscan($key, $cursor, $pattern = null, $count = null)
*
Expand Down
6 changes: 6 additions & 0 deletions src/RedisClient/Protocol/ProtocolInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@

interface ProtocolInterface {

/**
* @param string $command
* @return mixed
*/
public function sendRaw($command);

/**
* @param string[] $structure
* @return mixed
Expand Down
11 changes: 9 additions & 2 deletions src/RedisClient/Protocol/RedisProtocol.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,18 @@ protected function read() {
/**
* @inheritdoc
*/
public function send(array $structures) {
$this->write($this->packProtocolArray($structures));
public function sendRaw($command) {
$this->write($command);
return $response = $this->read();
}

/**
* @inheritdoc
*/
public function send(array $structures) {
return $this->sendRaw($this->packProtocolArray($structures));
}

/**
* @inheritdoc
*/
Expand Down
87 changes: 87 additions & 0 deletions tests/Integration/Version2x6/CommonTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php
/**
* This file is part of RedisClient.
* git: https://github.com/cheprasov/php-redis-client
*
* (C) Alexander Cheprasov <cheprasov.84@ya.ru>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Test\Integration\Version2x6;

use RedisClient\Client\Version\RedisClient2x6;

/**
* @see \RedisClient\Command\Traits\Version2x6\SetsCommandsTrait
*/
class CommonTest extends \PHPUnit_Framework_TestCase {

const TEST_REDIS_SERVER_1 = TEST_REDIS_SERVER_2x6_1;

/**
* @var RedisClient2x6
*/
protected static $Redis;

/**
* @inheritdoc
*/
public static function setUpBeforeClass() {
static::$Redis = new RedisClient2x6([
'server' => static::TEST_REDIS_SERVER_1,
'timeout' => 2,
]);
}

/**
* @inheritdoc
*/
public static function tearDownAfterClass() {
static::$Redis->flushall();
}

/**
* @inheritdoc
*/
protected function setUp() {
static::$Redis->flushall();
}

/**
* @see \RedisClient\Client\AbstractRedisClient::executeRawString
*/
public function test_executeRawString() {
$Redis = static::$Redis;

$this->assertSame('PONG', $Redis->executeRawString('PING'));

$this->assertSame(true, $Redis->executeRawString('SET foo bar'));
$this->assertSame('bar', $Redis->executeRawString('GET foo'));

$this->assertSame(true, $Redis->executeRawString('SET foo "hello world"'));
$this->assertSame('hello world', $Redis->executeRawString('GET foo'));

$this->assertSame(true, $Redis->executeRawString("SET \"\" \"String\r\nwith\r\nnewlines\""));
$this->assertSame("String\r\nwith\r\nnewlines", $Redis->executeRawString('GET ""'));
}

/**
* @see \RedisClient\Client\AbstractRedisClient::executeRaw
*/
public function test_executeRaw() {
$Redis = static::$Redis;

$this->assertSame('PONG', $Redis->executeRaw(['PING']));

$this->assertSame(true, $Redis->executeRaw(['SET', 'foo', 'bar']));
$this->assertSame('bar', $Redis->executeRaw(['GET', 'foo']));

$this->assertSame(true, $Redis->executeRaw(['SET', 'foo', 'hello world']));
$this->assertSame('hello world', $Redis->executeRaw(['GET', 'foo']));

$this->assertSame(true, $Redis->executeRaw(['SET', '', "String\r\nwith\r\nnewlines"]));
$this->assertSame("String\r\nwith\r\nnewlines", $Redis->executeRaw(['GET', '']));
}

}
32 changes: 32 additions & 0 deletions tests/Integration/Version2x8/CommonTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* This file is part of RedisClient.
* git: https://github.com/cheprasov/php-redis-client
*
* (C) Alexander Cheprasov <cheprasov.84@ya.ru>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Test\Integration\Version2x8;

include_once(__DIR__. '/../Version2x6/CommonTest.php');

use RedisClient\Client\Version\RedisClient2x8;
use Test\Integration\Version2x6\CommonTest as CommonTestVersion2x6;


class CommonTest extends CommonTestVersion2x6 {

const TEST_REDIS_SERVER_1 = TEST_REDIS_SERVER_2x8_1;

/**
* @inheritdoc
*/
public static function setUpBeforeClass() {
static::$Redis = new RedisClient2x8([
'server' => static::TEST_REDIS_SERVER_1,
'timeout' => 2,
]);
}
}
19 changes: 18 additions & 1 deletion tests/Integration/Version2x8/ConnectionCommandsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@
use Test\Integration\Version2x6\ConnectionCommandsTest as ConnectionCommandsTestVersion2x6;

/**
* @see \RedisClient\Command\Traits\Version2x6\ConnectionCommandsTrait
* @see \RedisClient\Command\Traits\Version2x8\ConnectionCommandsTrait
*/
class ConnectionCommandsTest extends ConnectionCommandsTestVersion2x6 {

const TEST_REDIS_SERVER_1 = TEST_REDIS_SERVER_2x8_1;

/**
* @var RedisClient2x8
*/
protected static $Redis;

/**
* @inheritdoc
*/
Expand All @@ -32,4 +37,16 @@ public static function setUpBeforeClass() {
]);
}

/**
* @see \RedisClient\Command\Traits\Version2x8\ConnectionCommandsTrait::ping
*/
public function test_ping() {
$Redis = static::$Redis;

$this->assertSame('PONG', $Redis->ping());
$this->assertSame('foo', $Redis->ping('foo'));
$this->assertSame("foo\r\nbar", $Redis->ping("foo\r\nbar"));
$this->assertSame("", $Redis->ping(""));
}

}
Loading