Skip to content

Commit 5792a96

Browse files
authored
Merge pull request #95 from fhjbalfoort/master
RedisStore use ClientInterface instead of Client
2 parents 7c7dcac + 3a8c69e commit 5792a96

File tree

4 files changed

+108
-9
lines changed

4 files changed

+108
-9
lines changed

src/Ganesha/Storage/Adapter/RedisStore.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
class RedisStore
99
{
1010
/**
11-
* @var \Predis\Client|\Redis|\RedisArray|\RedisCluster
11+
* @var \Predis\ClientInterface|\Redis|\RedisArray|\RedisCluster
1212
*/
1313
private $redis;
1414

1515
/**
16-
* @param \Redis|\RedisArray|\RedisCluster|\Predis\Client $redisClient
16+
* @param \Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface $redisClient
1717
*
1818
* @throws \InvalidArgumentException if redis client is not supported
1919
*/
@@ -23,10 +23,10 @@ public function __construct($redisClient)
2323
!$redisClient instanceof \Redis
2424
&& !$redisClient instanceof \RedisArray
2525
&& !$redisClient instanceof \RedisCluster
26-
&& !$redisClient instanceof \Predis\Client
26+
&& !$redisClient instanceof \Predis\ClientInterface
2727
) {
2828
throw new \InvalidArgumentException(sprintf(
29-
'%s() expects parameter 1 to be Redis, RedisArray, RedisCluster or Predis\Client, %s given',
29+
'%s() expects parameter 1 to be Redis, RedisArray, RedisCluster, or \Predis\ClientInterface %s given',
3030
__METHOD__,
3131
\is_object($redisClient) ? \get_class($redisClient) : \gettype($redisClient)
3232
));
@@ -178,7 +178,7 @@ public function get(string $key)
178178
{
179179
try {
180180
$result = $this->redis->get($key);
181-
if ($this->redis instanceof \Predis\Client && $result === null) {
181+
if ($this->redis instanceof \Predis\ClientInterface && $result === null) {
182182
return false;
183183
}
184184
return $result;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Ackintosh\Ganesha\Storage\Adapter;
4+
5+
use Predis\ClientInterface;
6+
7+
class PredisRedisClientInterfaceTest extends PredisRedisTest
8+
{
9+
protected function getRedisConnection(): ClientInterface
10+
{
11+
return new PredisRedisClientInterfaceTestDouble(
12+
parent::getRedisConnection()
13+
);
14+
}
15+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Ackintosh\Ganesha\Storage\Adapter;
5+
6+
use Predis\ClientInterface;
7+
use Predis\Command\CommandInterface;
8+
9+
final class PredisRedisClientInterfaceTestDouble implements ClientInterface
10+
{
11+
/**
12+
* @var ClientInterface
13+
*/
14+
private $client;
15+
16+
public function __construct(ClientInterface $client)
17+
{
18+
$this->client = $client;
19+
}
20+
21+
/**
22+
* {@inheritdoc}
23+
*/
24+
public function getProfile()
25+
{
26+
return $this->client->getProfile();
27+
}
28+
29+
/**
30+
* {@inheritdoc}
31+
*/
32+
public function getOptions()
33+
{
34+
return $this->client->getOptions();
35+
}
36+
37+
/**
38+
* {@inheritdoc}
39+
*/
40+
public function connect()
41+
{
42+
$this->client->connect();
43+
}
44+
45+
/**
46+
* {@inheritdoc}
47+
*/
48+
public function disconnect()
49+
{
50+
$this->client->disconnect();
51+
}
52+
53+
/**
54+
* {@inheritdoc}
55+
*/
56+
public function getConnection()
57+
{
58+
return $this->client->getConnection();
59+
}
60+
61+
/**
62+
* {@inheritdoc}
63+
*/
64+
public function createCommand($commandID, $arguments = [])
65+
{
66+
return $this->client->createCommand($commandID, $arguments);
67+
}
68+
69+
/**
70+
* {@inheritdoc}
71+
*/
72+
public function executeCommand(CommandInterface $command)
73+
{
74+
return $this->client->executeCommand($command);
75+
}
76+
77+
/**
78+
* {@inheritdoc}
79+
*/
80+
public function __call($commandID, $arguments)
81+
{
82+
return $this->executeCommand(
83+
$this->createCommand($commandID, $arguments)
84+
);
85+
}
86+
}

tests/Ackintosh/Ganesha/Storage/Adapter/PredisRedisTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@
33
namespace Ackintosh\Ganesha\Storage\Adapter;
44

55
use Predis\Client;
6+
use Predis\ClientInterface;
67

78
class PredisRedisTest extends AbstractRedisTest
89
{
9-
/**
10-
* @return Client
11-
*/
12-
protected function getRedisConnection(): Client
10+
protected function getRedisConnection(): ClientInterface
1311
{
1412
$r = new Client('tcp://' . (getenv('GANESHA_EXAMPLE_REDIS') ?: 'localhost'));
1513
$r->connect();

0 commit comments

Comments
 (0)