Skip to content

Commit ee57467

Browse files
committed
v160rc1
1 parent 6823e9a commit ee57467

File tree

12 files changed

+166
-35
lines changed

12 files changed

+166
-35
lines changed

src/RedisClient/Client/AbstractRedisClient.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
use RedisClient\Cluster\ClusterMap;
1414
use RedisClient\Command\Response\ResponseParser;
1515
use RedisClient\Exception\AskResponseException;
16+
use RedisClient\Exception\CommandNotFoundException;
1617
use RedisClient\Exception\ErrorResponseException;
18+
use RedisClient\Exception\InvalidArgumentException;
1719
use RedisClient\Exception\MovedResponseException;
1820
use RedisClient\Exception\TryAgainResponseException;
1921
use RedisClient\Pipeline\Pipeline;
@@ -166,8 +168,8 @@ protected function executeProtocolCommand(ProtocolInterface $Protocol, array $co
166168
} else {
167169
$this->ClusterMap->addCluster($response->getSlot(), $response->getServer());
168170
}
169-
$Protocol = $this->ClusterMap->getProtocolByServer($response->getServer());
170-
return $this->executeProtocolCommand($Protocol, $command, $params);
171+
$this->Protocol = $this->ClusterMap->getProtocolByServer($response->getServer());
172+
return $this->executeProtocolCommand($this->Protocol, $command, $params);
171173
}
172174
if ($response instanceof AskResponseException) {
173175
$config = $this->getConfig();
@@ -251,7 +253,7 @@ protected function getStructure(array $command, array $params = null) {
251253
/**
252254
* @param null|Pipeline|\Closure $Pipeline
253255
* @return mixed|Pipeline
254-
* @throws \InvalidArgumentException
256+
* @throws InvalidArgumentException
255257
*/
256258
public function pipeline($Pipeline = null) {
257259
if (!$Pipeline) {
@@ -263,7 +265,7 @@ public function pipeline($Pipeline = null) {
263265
if ($Pipeline instanceof PipelineInterface) {
264266
return $this->executePipeline($Pipeline);
265267
}
266-
throw new \InvalidArgumentException();
268+
throw new InvalidArgumentException();
267269
}
268270

269271
/**
@@ -342,7 +344,7 @@ public function __call($name , array $arguments) {
342344
if ($method = $this->getMethodNameForReservedWord($name)) {
343345
return call_user_func_array([$this, $method], $arguments);
344346
}
345-
throw new \Exception('Call to undefined method '. static::class. '::'. $name);
347+
throw new CommandNotFoundException('Call to undefined method '. static::class. '::'. $name);
346348
}
347349

348350
}

src/RedisClient/ClientFactory.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public static function create($config = null) {
8484
* @param string $version
8585
* @param null|array $config
8686
* @return RedisClient2x6|RedisClient2x8|RedisClient3x0|RedisClient3x2|RedisClient4x0
87+
* @throws InvalidArgumentException
8788
*/
8889
public static function createClientByVersion($version, $config = null) {
8990
list($major, $minor, $patch) = explode('.', $version .'.0.0');
@@ -100,7 +101,7 @@ public static function createClientByVersion($version, $config = null) {
100101
}
101102
}
102103
if (empty($class)) {
103-
throw new \InvalidArgumentException(
104+
throw new InvalidArgumentException(
104105
'RedisClient does not support Redis version '. $version .'. Please, use version '. end($versions)
105106
);
106107
}

src/RedisClient/Cluster/ClusterMap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public function getServerBySlot($slot) {
103103
return $server;
104104
}
105105
}
106-
return null;
106+
return isset($server) ? $server : null;
107107
}
108108

109109
/**

src/RedisClient/Command/Parameter/Parameter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*/
1111
namespace RedisClient\Command\Parameter;
1212

13-
use InvalidArgumentException;
13+
use RedisClient\Exception\InvalidArgumentException;
1414

1515
class Parameter {
1616

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
*/
1111
namespace RedisClient\Command\Traits\Version2x6;
1212

13+
use RedisClient\Exception\InvalidArgumentException;
14+
1315
/**
1416
* PubSub Commands
1517
* @link http://redis.io/commands#pubsub
@@ -25,10 +27,11 @@ trait PubSubCommandsTrait {
2527
* @param string|string[] $patterns
2628
* @param \Closure|string|array $callback
2729
* @return string[]
30+
* @throws InvalidArgumentException
2831
*/
2932
public function psubscribe($patterns, $callback) {
3033
if (!is_callable($callback)) {
31-
throw new \InvalidArgumentException('Function $callback is not callable');
34+
throw new InvalidArgumentException('Function $callback is not callable');
3235
}
3336
return $this->subscribeCommand(['PSUBSCRIBE'], ['PUNSUBSCRIBE'], (array)$patterns, $callback);
3437
}
@@ -70,10 +73,11 @@ public function punsubscribe($patterns = null) {
7073
* @param string|string[] $channels
7174
* @param \Closure|string|array $callback
7275
* @return string[]
76+
* @throws InvalidArgumentException
7377
*/
7478
public function subscribe($channels, $callback) {
7579
if (!is_callable($callback)) {
76-
throw new \InvalidArgumentException('Function $callback is not callable');
80+
throw new InvalidArgumentException('Function $callback is not callable');
7781
}
7882
return $this->subscribeCommand(['SUBSCRIBE'], ['UNSUBSCRIBE'], (array)$channels, $callback);
7983
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
*/
1111
namespace RedisClient\Command\Traits\Version2x6;
1212

13-
use InvalidArgumentException;
1413
use RedisClient\Command\Parameter\Parameter;
14+
use RedisClient\Exception\InvalidArgumentException;
1515

1616
/**
1717
* Strings Commands
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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\Exception;
12+
13+
class CommandNotFoundException extends RedisException {
14+
15+
}

src/RedisClient/Pipeline/AbstractPipeline.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
namespace RedisClient\Pipeline;
1212

1313
use RedisClient\Command\Response\ResponseParser;
14+
use RedisClient\Exception\CommandNotFoundException;
1415
use RedisClient\Exception\ErrorException;
1516

1617
abstract class AbstractPipeline implements PipelineInterface {
@@ -121,7 +122,7 @@ public function __call($name , array $arguments) {
121122
if ($method = $this->getMethodNameForReservedWord($name)) {
122123
return call_user_func_array([$this, $method], $arguments);
123124
}
124-
throw new \Exception('Call to undefined method '. static::class. '::'. $name);
125+
throw new CommandNotFoundException('Call to undefined method '. static::class. '::'. $name);
125126
}
126127

127128
}

src/RedisClient/Protocol/ProtocolInterface.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ interface ProtocolInterface {
1919
*/
2020
public function setConnection(ConnectionInterface $Connection);
2121

22+
/**
23+
* @return ConnectionInterface $Connection
24+
*/
25+
public function getConnection();
26+
2227
/**
2328
* @param string $command
2429
* @return mixed

tests/Integration/Version3x0/ClusterTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,12 @@ public function test_addClusterSlotsOnError() {
141141
$Redis->set('foo', 'bar');
142142
$this->assertSame([12182 => '127.0.0.1:7003'], $ClusterMap->getClusters());
143143
$Redis->set('foo1', 'bar');
144-
$this->assertSame([13431 => '127.0.0.1:7003'], $ClusterMap->getClusters());
144+
$this->assertSame([12182 => '127.0.0.1:7003'], $ClusterMap->getClusters());
145145
$Redis->set('foo2', 'bar');
146146
$this->assertSame(
147147
[
148148
1044 => '127.0.0.1:7001',
149-
13431 => '127.0.0.1:7003'
149+
12182 => '127.0.0.1:7003'
150150
],
151151
$ClusterMap->getClusters()
152152
);

0 commit comments

Comments
 (0)