Skip to content

Commit 7c60fa1

Browse files
committed
Merge pull request #39 from cheprasov/dev-1.2.3
v1.2.3
2 parents 1e8415a + 9df80af commit 7c60fa1

20 files changed

+280
-17
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## CHANGELOG
22

3+
### v1.2.3 (2016-05-02)
4+
- Fixed command **PING** for Redis <= 2.6.
5+
- Added common tests.
6+
37
### v1.2.2 (2016-03-30)
48
- Fixed annotations and phpDocs.
59
- Fixed some tests.

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[![MIT license](http://img.shields.io/badge/license-MIT-brightgreen.svg)](http://opensource.org/licenses/MIT)
22
[![Latest Stable Version](https://poser.pugx.org/cheprasov/php-redis-client/v/stable)](https://packagist.org/packages/cheprasov/php-redis-client)
33
[![Total Downloads](https://poser.pugx.org/cheprasov/php-redis-client/downloads)](https://packagist.org/packages/cheprasov/php-redis-client)
4-
# RedisClient v1.2.2 for PHP >= 5.5
4+
# RedisClient v1.2.3 for PHP >= 5.5
55

66
## About
77
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__
@@ -15,6 +15,7 @@ RedisClient is a fast, fully-functional and user-friendly client for Redis, opti
1515
- Connections to Redis are established lazily by the client upon the first command.
1616
- Easy to use with IDE, client has PHPDocs for all supported versions.
1717
- By default, the client works with the latest stable version of Redis.
18+
- About **6.5-8.5% faster** than predis (based on this test: https://github.com/cheprasov/php-redis-client-vs-predis-test)
1819

1920
## Usage
2021

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cheprasov/php-redis-client",
3-
"version": "1.2.2",
3+
"version": "1.2.3",
44
"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",
55
"homepage": "http://github.com/cheprasov/php-redis-client",
66
"minimum-stability": "stable",

src/RedisClient/Client/AbstractRedisClient.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
abstract class AbstractRedisClient {
2222

23-
const VERSION = '1.2.2';
23+
const VERSION = '1.2.3';
2424

2525
const CONFIG_SERVER = 'server';
2626
const CONFIG_TIMEOUT = 'timeout';
@@ -184,6 +184,7 @@ public function executeRaw($structure) {
184184
}
185185

186186
/**
187+
* Command will parsed by the client, before sent to server
187188
* @param string $command
188189
* @return mixed
189190
*/

src/RedisClient/Command/Traits/Version2x6/ConnectionCommandsTrait.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,14 @@ public function echoMessage($message) {
4545
}
4646

4747
/**
48-
* PING [message]
48+
* PING
4949
* Available since 1.0.0.
5050
* @link http://redis.io/commands/ping
5151
*
52-
* @param string $message
5352
* @return string Returns message
5453
*/
55-
public function ping($message = null) {
56-
return $this->returnCommand(['PING'], isset($message) ? [$message] : null);
54+
public function ping() {
55+
return $this->returnCommand(['PING']);
5756
}
5857

5958
/**

src/RedisClient/Command/Traits/Version2x8/CommandsTrait.php

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
namespace RedisClient\Command\Traits\Version2x8;
1212

1313
use RedisClient\Command\Traits\AbstractCommandsTrait;
14-
use RedisClient\Command\Traits\Version2x6\ConnectionCommandsTrait;
1514
use RedisClient\Command\Traits\Version2x6\ListsCommandsTrait;
1615
use RedisClient\Command\Traits\Version2x6\ScriptingCommandsTrait;
1716
use RedisClient\Command\Traits\Version2x6\TransactionsCommandsTrait;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
/**
3+
* This file is part of RedisClient.
4+
* git: https://github.com/cheprasov/php-redis-client
5+
*
6+
* (C) Alexander Cheprasov <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
namespace RedisClient\Command\Traits\Version2x8;
12+
13+
use RedisClient\Command\Traits\Version2x6\ConnectionCommandsTrait as ConnectionCommandsTraitVersion2x6;
14+
15+
/**
16+
* Connection Commands
17+
* @link http://redis.io/commands#connection
18+
*
19+
* @method string echo($message)
20+
*/
21+
trait ConnectionCommandsTrait {
22+
23+
use ConnectionCommandsTraitVersion2x6;
24+
25+
/**
26+
* PING [message]
27+
* Available since 1.0.0.
28+
* @link http://redis.io/commands/ping
29+
*
30+
* @param string $message
31+
* @return string Returns message
32+
*/
33+
public function ping($message = null) {
34+
return $this->returnCommand(['PING'], isset($message) ? [$message] : null);
35+
}
36+
37+
}

src/RedisClient/Command/Traits/Version3x0/CommandsTrait.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
namespace RedisClient\Command\Traits\Version3x0;
1212

1313
use RedisClient\Command\Traits\AbstractCommandsTrait;
14-
use RedisClient\Command\Traits\Version2x6\ConnectionCommandsTrait;
14+
use RedisClient\Command\Traits\Version2x8\ConnectionCommandsTrait;
1515
use RedisClient\Command\Traits\Version2x8\HashesCommandsTrait;
1616
use RedisClient\Command\Traits\Version2x6\ListsCommandsTrait;
1717
use RedisClient\Command\Traits\Version2x6\ScriptingCommandsTrait;

src/RedisClient/Command/Traits/Version3x2/CommandsTrait.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use RedisClient\Command\Traits\Version2x8\LatencyCommandsTrait;
1515
use RedisClient\Command\Traits\Version2x8\PubSubCommandsTrait;
1616
use RedisClient\Command\Traits\Version3x0\ClusterCommandsTrait;
17-
use RedisClient\Command\Traits\Version2x6\ConnectionCommandsTrait;
17+
use RedisClient\Command\Traits\Version2x8\ConnectionCommandsTrait;
1818
use RedisClient\Command\Traits\Version2x8\HyperLogLogCommandsTrait;
1919
use RedisClient\Command\Traits\Version2x6\ListsCommandsTrait;
2020
use RedisClient\Command\Traits\Version3x0\SortedSetsCommandsTrait;

src/RedisClient/Pipeline/Version/Pipeline2x6.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* @method Pipeline2x6 auth($password)
2121
* @method Pipeline2x6 echo($message)
2222
* @method Pipeline2x6 echoMessage($message) - alias method for reversed word <echo>
23-
* @method Pipeline2x6 ping($message = null)
23+
* @method Pipeline2x6 ping()
2424
* @method Pipeline2x6 quit()
2525
* @method Pipeline2x6 select($db)
2626
*

src/RedisClient/Pipeline/Version/Pipeline2x8.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* @method Pipeline2x8 auth($password)
2121
* @method Pipeline2x8 echo($message)
2222
* @method Pipeline2x8 echoMessage($message) - alias method for reversed word <echo>
23-
* @method Pipeline2x8 ping($message = null)
23+
* -method Pipeline2x8 ping()
2424
* @method Pipeline2x8 quit()
2525
* @method Pipeline2x8 select($db)
2626
*
@@ -186,6 +186,9 @@
186186
*
187187
* Redis version 2.8
188188
*
189+
* Connection
190+
* @method Pipeline2x8 ping($message = null)
191+
*
189192
* Hashes
190193
* @method Pipeline2x8 hscan($key, $cursor, $pattern = null, $count = null)
191194
*

src/RedisClient/Pipeline/Version/Pipeline3x0.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* @method Pipeline3x0 auth($password)
2121
* @method Pipeline3x0 echo($message)
2222
* @method Pipeline3x0 echoMessage($message) - alias method for reversed word <echo>
23-
* @method Pipeline3x0 ping($message = null)
23+
* -method Pipeline3x0 ping()
2424
* @method Pipeline3x0 quit()
2525
* @method Pipeline3x0 select($db)
2626
*
@@ -186,6 +186,9 @@
186186
*
187187
* Redis version 2.8
188188
*
189+
* Connection
190+
* @method Pipeline3x0 ping($message = null)
191+
*
189192
* Hashes
190193
* @method Pipeline3x0 hscan($key, $cursor, $pattern = null, $count = null)
191194
*

src/RedisClient/Pipeline/Version/Pipeline3x2.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* @method Pipeline3x2 auth($password)
2121
* @method Pipeline3x2 echo($message)
2222
* @method Pipeline3x2 echoMessage($message) - alias method for reversed word <echo>
23-
* @method Pipeline3x2 ping($message = null)
23+
* -method Pipeline3x2 ping()
2424
* @method Pipeline3x2 quit()
2525
* @method Pipeline3x2 select($db)
2626
*
@@ -186,6 +186,9 @@
186186
*
187187
* Redis version 2.8
188188
*
189+
* Connection
190+
* @method Pipeline3x2 ping($message = null)
191+
*
189192
* Hashes
190193
* @method Pipeline3x2 hscan($key, $cursor, $pattern = null, $count = null)
191194
*

src/RedisClient/Protocol/ProtocolInterface.php

+6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212

1313
interface ProtocolInterface {
1414

15+
/**
16+
* @param string $command
17+
* @return mixed
18+
*/
19+
public function sendRaw($command);
20+
1521
/**
1622
* @param string[] $structure
1723
* @return mixed

src/RedisClient/Protocol/RedisProtocol.php

+9-2
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,18 @@ protected function read() {
141141
/**
142142
* @inheritdoc
143143
*/
144-
public function send(array $structures) {
145-
$this->write($this->packProtocolArray($structures));
144+
public function sendRaw($command) {
145+
$this->write($command);
146146
return $response = $this->read();
147147
}
148148

149+
/**
150+
* @inheritdoc
151+
*/
152+
public function send(array $structures) {
153+
return $this->sendRaw($this->packProtocolArray($structures));
154+
}
155+
149156
/**
150157
* @inheritdoc
151158
*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
/**
3+
* This file is part of RedisClient.
4+
* git: https://github.com/cheprasov/php-redis-client
5+
*
6+
* (C) Alexander Cheprasov <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
namespace Test\Integration\Version2x6;
12+
13+
use RedisClient\Client\Version\RedisClient2x6;
14+
15+
/**
16+
* @see \RedisClient\Command\Traits\Version2x6\SetsCommandsTrait
17+
*/
18+
class CommonTest extends \PHPUnit_Framework_TestCase {
19+
20+
const TEST_REDIS_SERVER_1 = TEST_REDIS_SERVER_2x6_1;
21+
22+
/**
23+
* @var RedisClient2x6
24+
*/
25+
protected static $Redis;
26+
27+
/**
28+
* @inheritdoc
29+
*/
30+
public static function setUpBeforeClass() {
31+
static::$Redis = new RedisClient2x6([
32+
'server' => static::TEST_REDIS_SERVER_1,
33+
'timeout' => 2,
34+
]);
35+
}
36+
37+
/**
38+
* @inheritdoc
39+
*/
40+
public static function tearDownAfterClass() {
41+
static::$Redis->flushall();
42+
}
43+
44+
/**
45+
* @inheritdoc
46+
*/
47+
protected function setUp() {
48+
static::$Redis->flushall();
49+
}
50+
51+
/**
52+
* @see \RedisClient\Client\AbstractRedisClient::executeRawString
53+
*/
54+
public function test_executeRawString() {
55+
$Redis = static::$Redis;
56+
57+
$this->assertSame('PONG', $Redis->executeRawString('PING'));
58+
59+
$this->assertSame(true, $Redis->executeRawString('SET foo bar'));
60+
$this->assertSame('bar', $Redis->executeRawString('GET foo'));
61+
62+
$this->assertSame(true, $Redis->executeRawString('SET foo "hello world"'));
63+
$this->assertSame('hello world', $Redis->executeRawString('GET foo'));
64+
65+
$this->assertSame(true, $Redis->executeRawString("SET \"\" \"String\r\nwith\r\nnewlines\""));
66+
$this->assertSame("String\r\nwith\r\nnewlines", $Redis->executeRawString('GET ""'));
67+
}
68+
69+
/**
70+
* @see \RedisClient\Client\AbstractRedisClient::executeRaw
71+
*/
72+
public function test_executeRaw() {
73+
$Redis = static::$Redis;
74+
75+
$this->assertSame('PONG', $Redis->executeRaw(['PING']));
76+
77+
$this->assertSame(true, $Redis->executeRaw(['SET', 'foo', 'bar']));
78+
$this->assertSame('bar', $Redis->executeRaw(['GET', 'foo']));
79+
80+
$this->assertSame(true, $Redis->executeRaw(['SET', 'foo', 'hello world']));
81+
$this->assertSame('hello world', $Redis->executeRaw(['GET', 'foo']));
82+
83+
$this->assertSame(true, $Redis->executeRaw(['SET', '', "String\r\nwith\r\nnewlines"]));
84+
$this->assertSame("String\r\nwith\r\nnewlines", $Redis->executeRaw(['GET', '']));
85+
}
86+
87+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
/**
3+
* This file is part of RedisClient.
4+
* git: https://github.com/cheprasov/php-redis-client
5+
*
6+
* (C) Alexander Cheprasov <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
namespace Test\Integration\Version2x8;
12+
13+
include_once(__DIR__. '/../Version2x6/CommonTest.php');
14+
15+
use RedisClient\Client\Version\RedisClient2x8;
16+
use Test\Integration\Version2x6\CommonTest as CommonTestVersion2x6;
17+
18+
19+
class CommonTest extends CommonTestVersion2x6 {
20+
21+
const TEST_REDIS_SERVER_1 = TEST_REDIS_SERVER_2x8_1;
22+
23+
/**
24+
* @inheritdoc
25+
*/
26+
public static function setUpBeforeClass() {
27+
static::$Redis = new RedisClient2x8([
28+
'server' => static::TEST_REDIS_SERVER_1,
29+
'timeout' => 2,
30+
]);
31+
}
32+
}

tests/Integration/Version2x8/ConnectionCommandsTest.php

+18-1
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,17 @@
1616
use Test\Integration\Version2x6\ConnectionCommandsTest as ConnectionCommandsTestVersion2x6;
1717

1818
/**
19-
* @see \RedisClient\Command\Traits\Version2x6\ConnectionCommandsTrait
19+
* @see \RedisClient\Command\Traits\Version2x8\ConnectionCommandsTrait
2020
*/
2121
class ConnectionCommandsTest extends ConnectionCommandsTestVersion2x6 {
2222

2323
const TEST_REDIS_SERVER_1 = TEST_REDIS_SERVER_2x8_1;
2424

25+
/**
26+
* @var RedisClient2x8
27+
*/
28+
protected static $Redis;
29+
2530
/**
2631
* @inheritdoc
2732
*/
@@ -32,4 +37,16 @@ public static function setUpBeforeClass() {
3237
]);
3338
}
3439

40+
/**
41+
* @see \RedisClient\Command\Traits\Version2x8\ConnectionCommandsTrait::ping
42+
*/
43+
public function test_ping() {
44+
$Redis = static::$Redis;
45+
46+
$this->assertSame('PONG', $Redis->ping());
47+
$this->assertSame('foo', $Redis->ping('foo'));
48+
$this->assertSame("foo\r\nbar", $Redis->ping("foo\r\nbar"));
49+
$this->assertSame("", $Redis->ping(""));
50+
}
51+
3552
}

0 commit comments

Comments
 (0)