Skip to content

Commit 1ec28ea

Browse files
committed
Merge pull request #23 from cheprasov/dev-with-versions
Added Server Commands Test
2 parents 40d5829 + b56c64e commit 1ec28ea

24 files changed

+439
-30
lines changed

src/RedisClient/Command/Response/ResponseParser.php

+27
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class ResponseParser {
1717
const PARSE_TIME = 3;
1818
const PARSE_INFO = 4;
1919
const PARSE_GEO_ARRAY = 5;
20+
const PARSE_CLIENT_LIST = 6;
2021

2122
/**
2223
* @param int $type
@@ -35,6 +36,8 @@ public static function parse($type, $response) {
3536
return self::parseInfo($response);
3637
case self::PARSE_GEO_ARRAY:
3738
return self::parseGeoArray($response);
39+
case self::PARSE_CLIENT_LIST:
40+
return self::parseClientList($response);
3841
default:
3942
return $response;
4043
}
@@ -55,6 +58,30 @@ public static function parseAssocArray($response) {
5558
return $array;
5659
}
5760

61+
/**
62+
* @param string[] $response
63+
* @return array
64+
*/
65+
public static function parseClientList($response) {
66+
if (!is_string($response)) {
67+
return $response;
68+
}
69+
$array = [];
70+
foreach (explode("\n", $response) as $client) {
71+
$c = [];
72+
foreach (explode(' ', $client) as $param) {
73+
$args = explode('=', $param, 2);
74+
if (isset($args[0], $args[1]) && ($key = trim($args[0]))) {
75+
$c[$key] = trim($args[1]);
76+
}
77+
}
78+
if ($c) {
79+
$array[] = $c;
80+
}
81+
}
82+
return $array;
83+
}
84+
5885
/**
5986
* @param string[] $response
6087
* @return array

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

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ trait CommandsTrait {
2020
use HashesCommandsTrait;
2121
use KeysCommandsTrait;
2222
use ListsCommandsTrait;
23+
use PubSubCommandsTrait;
2324
use ScriptingCommandsTrait;
2425
use ServerCommandsTrait;
2526
use SetsCommandsTrait;

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function clientKill($addr = null, $clientId = null, $type = null, $addr2
9595
* @return string
9696
*/
9797
public function clientList() {
98-
return $this->returnCommand(['CLIENT', 'LIST']);
98+
return $this->returnCommand(['CLIENT', 'LIST'], null, ResponseParser::PARSE_CLIENT_LIST);
9999
}
100100

101101
/**

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

+14
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,20 @@ public function getrange($key, $start, $end) {
137137
return $this->returnCommand(['GETRANGE'], [$key, $start, $end]);
138138
}
139139

140+
/**
141+
* SUBSTR key start end
142+
* @deprecated
143+
* @see StringsCommandsTrait::getrange
144+
*
145+
* @param string $key
146+
* @param int $start
147+
* @param int $end
148+
* @return string
149+
*/
150+
public function substr($key, $start, $end) {
151+
return $this->returnCommand(['SUBSTR'], [$key, $start, $end]);
152+
}
153+
140154
/**
141155
* GETSET key value
142156
* Available since 1.0.0.

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

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ trait CommandsTrait {
2626
use KeysCommandsTrait;
2727
use LatencyCommandsTrait;
2828
use ListsCommandsTrait;
29+
use PubSubCommandsTrait;
2930
use ScriptingCommandsTrait;
3031
use ServerCommandsTrait;
3132
use SetsCommandsTrait;

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
*/
1111
namespace RedisClient\Command\Traits\Version2x8;
1212

13-
use RedisClient\Command\Traits\Version2x6\HashesCommandsTrait as HashesCommandsTraitVersion26;
13+
use RedisClient\Command\Traits\Version2x6\HashesCommandsTrait as HashesCommandsTraitVersion2x6;
1414

1515
/**
1616
* trait HashesCommandsTrait
1717
* @link http://redis.io/commands#hash
1818
*/
1919
trait HashesCommandsTrait {
2020

21-
use HashesCommandsTraitVersion26;
21+
use HashesCommandsTraitVersion2x6;
2222

2323
/**
2424
* HSCAN key cursor [MATCH pattern] [COUNT count]

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

+28
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,32 @@ public function pfmerge($destkey, $sourcekeys) {
5858
return $this->returnCommand(['PFMERGE'], [$destkey, (array) $sourcekeys]);
5959
}
6060

61+
// /**
62+
// * PFDEBUG <subcommand> <key> ... args ...
63+
// * Available since 2.8.9.
64+
// * @link http://download.redis.io/redis-stable/src/hyperloglog.c
65+
// * @debug
66+
// * @deprecated only for debug
67+
// *
68+
// * @param string $subcommand GETREG|DECODE|ENCODING|TODENSE
69+
// * @param string $key
70+
// * @return mixed
71+
// */
72+
// public function pfdebug($subcommand, $key) {
73+
// return $this->returnCommand(['PFDEBUG'], [$subcommand, $key]);
74+
// }
75+
76+
// /**
77+
// * PFSELFTEST
78+
// * Available since 2.8.9.
79+
// * @link http://download.redis.io/redis-stable/src/hyperloglog.c
80+
// * @debug
81+
// * @deprecated only for debug
82+
// *
83+
// * @return mixed
84+
// */
85+
// public function pfselftest() {
86+
// return $this->returnCommand(['PFSELFTEST']);
87+
// }
88+
6189
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
*/
1111
namespace RedisClient\Command\Traits\Version2x8;
1212

13-
use RedisClient\Command\Traits\Version2x6\KeysCommandsTrait as KeysCommandsTraitVersion26;
13+
use RedisClient\Command\Traits\Version2x6\KeysCommandsTrait as KeysCommandsTraitVersion2x6;
1414

1515
/**
1616
* trait KeysCommandsTrait
1717
*/
1818
trait KeysCommandsTrait {
1919

20-
use KeysCommandsTraitVersion26;
20+
use KeysCommandsTraitVersion2x6;
2121

2222
/**
2323
* SCAN cursor [MATCH pattern] [COUNT count]

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
*/
1111
namespace RedisClient\Command\Traits\Version2x8;
1212

13-
use RedisClient\Command\Traits\Version2x6\PubSubCommandsTrait as PubSubCommandsTraitVersion26;
13+
use RedisClient\Command\Traits\Version2x6\PubSubCommandsTrait as PubSubCommandsTraitVersion2x6;
1414

1515
/**
1616
* PubSub
1717
* @link http://redis.io/commands#pubsub
1818
*/
1919
trait PubSubCommandsTrait {
2020

21-
use PubSubCommandsTraitVersion26;
21+
use PubSubCommandsTraitVersion2x6;
2222

2323
/**
2424
* PUBSUB subcommand [argument [argument ...]]

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

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

1313
use RedisClient\Command\Parameter\Parameter;
14-
use RedisClient\Command\Traits\Version2x6\ServerCommandsTrait as ServerCommandsTraitVersion26;
14+
use RedisClient\Command\Traits\Version2x6\ServerCommandsTrait as ServerCommandsTraitVersion2x6;
1515

1616
trait ServerCommandsTrait {
1717

18-
use ServerCommandsTraitVersion26;
18+
use ServerCommandsTraitVersion2x6;
1919

2020
/**
2121
* COMMAND
@@ -50,15 +50,15 @@ public function commandCount() {
5050
* @return string[] List of keys from your command.
5151
*/
5252
public function commandGetkeys($command) {
53-
return $this->returnCommand(['COMMAND', 'GETKEYS'], [Parameter::command($command)]);
53+
return $this->returnCommand(['COMMAND', 'GETKEYS'], Parameter::command($command));
5454
}
5555

5656
/**
5757
* COMMAND INFO command-name [command-name ...]
5858
* Available since 2.8.13.
5959
* Time complexity: O(N) when N is number of commands to look up
6060
*
61-
* @param string[] $commandNames
61+
* @param string|string[] $commandNames
6262
* @return array Nested list of command details.
6363
*/
6464
public function commandInfo($commandNames) {

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
*/
1111
namespace RedisClient\Command\Traits\Version2x8;
1212

13-
use RedisClient\Command\Traits\Version2x6\SetsCommandsTrait as SetsCommandsTraitVersion26;
13+
use RedisClient\Command\Traits\Version2x6\SetsCommandsTrait as SetsCommandsTraitVersion2x6;
1414

1515
trait SetsCommandsTrait {
1616

17-
use SetsCommandsTraitVersion26;
17+
use SetsCommandsTraitVersion2x6;
1818

1919
/**
2020
* SSCAN key cursor [MATCH pattern] [COUNT count]

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
namespace RedisClient\Command\Traits\Version2x8;
1212

1313
use RedisClient\Command\Parameter\Parameter;
14-
use RedisClient\Command\Traits\Version2x6\SortedSetsCommandsTrait as SortedSetsCommandsTraitVersion26;
14+
use RedisClient\Command\Traits\Version2x6\SortedSetsCommandsTrait as SortedSetsCommandsTraitVersion2x6;
1515

1616
/**
1717
* trait SortedSetsCommandsTrait
1818
* @link http://redis.io/topics/data-types#sorted-sets
1919
*/
2020
trait SortedSetsCommandsTrait {
2121

22-
use SortedSetsCommandsTraitVersion26;
22+
use SortedSetsCommandsTraitVersion2x6;
2323

2424
/**
2525
* ZLEXCOUNT key min max

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
*/
1111
namespace RedisClient\Command\Traits\Version2x8;
1212

13-
use RedisClient\Command\Traits\Version2x6\StringsCommandsTrait as StringsCommandsTraitVersion26;
13+
use RedisClient\Command\Traits\Version2x6\StringsCommandsTrait as StringsCommandsTraitVersion2x6;
1414

1515
trait StringsCommandsTrait {
1616

17-
use StringsCommandsTraitVersion26;
17+
use StringsCommandsTraitVersion2x6;
1818

1919
/**
2020
* BITPOS key bit [start] [end]

src/RedisClient/Command/Traits/Version2x9/ServerCommandsTrait.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
*/
1111
namespace RedisClient\Command\Traits\Version2x9;
1212

13-
use RedisClient\Command\Traits\Version2x8\ServerCommandsTrait as ServerCommandsTraitVersion28;
13+
use RedisClient\Command\Traits\Version2x8\ServerCommandsTrait as ServerCommandsTraitVersion2x8;
1414
trait ServerCommandsTrait {
1515

16-
use ServerCommandsTraitVersion28;
16+
use ServerCommandsTraitVersion2x8;
1717

1818
/**
1919
* CLIENT PAUSE timeout

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

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use RedisClient\Command\Traits\Version2x6\ListsCommandsTrait;
1717
use RedisClient\Command\Traits\Version2x6\ScriptingCommandsTrait;
1818
use RedisClient\Command\Traits\Version2x8\LatencyCommandsTrait;
19+
use RedisClient\Command\Traits\Version2x8\PubSubCommandsTrait;
1920
use RedisClient\Command\Traits\Version2x9\ServerCommandsTrait;
2021
use RedisClient\Command\Traits\Version2x8\SetsCommandsTrait;
2122
use RedisClient\Command\Traits\Version2x8\StringsCommandsTrait;
@@ -33,6 +34,7 @@ trait CommandsTrait {
3334
use KeysCommandsTrait;
3435
use LatencyCommandsTrait;
3536
use ListsCommandsTrait;
37+
use PubSubCommandsTrait;
3638
use ScriptingCommandsTrait;
3739
use ServerCommandsTrait;
3840
use SetsCommandsTrait;

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
*/
1111
namespace RedisClient\Command\Traits\Version3x0;
1212

13-
use RedisClient\Command\Traits\Version2x8\KeysCommandsTrait as KeysCommandsTraitVersion28;
13+
use RedisClient\Command\Traits\Version2x8\KeysCommandsTrait as KeysCommandsTraitVersion2x8;
1414

1515
/**
1616
* trait KeysCommandsTrait
1717
*/
1818
trait KeysCommandsTrait {
1919

20-
use KeysCommandsTraitVersion28;
20+
use KeysCommandsTraitVersion2x8;
2121

2222
/**
2323
* EXISTS key [key ...]

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

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

1313
use RedisClient\Command\Traits\AbstractCommandsTrait;
1414
use RedisClient\Command\Traits\Version2x8\LatencyCommandsTrait;
15+
use RedisClient\Command\Traits\Version2x8\PubSubCommandsTrait;
1516
use RedisClient\Command\Traits\Version3x0\ClusterCommandsTrait;
1617
use RedisClient\Command\Traits\Version2x6\ConnectionCommandsTrait;
1718
use RedisClient\Command\Traits\Version2x8\HyperLogLogCommandsTrait;
@@ -35,6 +36,7 @@ trait CommandsTrait {
3536
use KeysCommandsTrait;
3637
use LatencyCommandsTrait;
3738
use ListsCommandsTrait;
39+
use PubSubCommandsTrait;
3840
use ScriptingCommandsTrait;
3941
use ServerCommandsTrait;
4042
use SetsCommandsTrait;

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
*/
1111
namespace RedisClient\Command\Traits\Version3x2;
1212

13-
use RedisClient\Command\Traits\Version2x8\HashesCommandsTrait as HashesCommandsTraitVersion28;
13+
use RedisClient\Command\Traits\Version2x8\HashesCommandsTrait as HashesCommandsTraitVersion2x8;
1414

1515
/**
1616
* trait HashesCommandsTrait
1717
* @link http://redis.io/commands#hash
1818
*/
1919
trait HashesCommandsTrait {
2020

21-
use HashesCommandsTraitVersion28;
21+
use HashesCommandsTraitVersion2x8;
2222

2323
/**
2424
* HSTRLEN key field

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
*/
1111
namespace RedisClient\Command\Traits\Version3x2;
1212

13-
use RedisClient\Command\Traits\Version2x8\SetsCommandsTrait as SetsCommandsTraitVersion28;
13+
use RedisClient\Command\Traits\Version2x8\SetsCommandsTrait as SetsCommandsTraitVersion2x8;
1414

1515
trait SetsCommandsTrait {
1616

17-
use SetsCommandsTraitVersion28;
17+
use SetsCommandsTraitVersion2x8;
1818

1919
/**
2020
* SPOP key [count]

0 commit comments

Comments
 (0)