Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RedisStore use ClientInterface instead of Client #95

Merged
merged 2 commits into from
Apr 26, 2022
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
10 changes: 5 additions & 5 deletions src/Ganesha/Storage/Adapter/RedisStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
class RedisStore
{
/**
* @var \Predis\Client|\Redis|\RedisArray|\RedisCluster
* @var \Predis\ClientInterface|\Redis|\RedisArray|\RedisCluster
*/
private $redis;

/**
* @param \Redis|\RedisArray|\RedisCluster|\Predis\Client $redisClient
* @param \Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface $redisClient
*
* @throws \InvalidArgumentException if redis client is not supported
*/
Expand All @@ -23,10 +23,10 @@ public function __construct($redisClient)
!$redisClient instanceof \Redis
&& !$redisClient instanceof \RedisArray
&& !$redisClient instanceof \RedisCluster
&& !$redisClient instanceof \Predis\Client
&& !$redisClient instanceof \Predis\ClientInterface
) {
throw new \InvalidArgumentException(sprintf(
'%s() expects parameter 1 to be Redis, RedisArray, RedisCluster or Predis\Client, %s given',
'%s() expects parameter 1 to be Redis, RedisArray, RedisCluster, or \Predis\ClientInterface %s given',
__METHOD__,
\is_object($redisClient) ? \get_class($redisClient) : \gettype($redisClient)
));
Expand Down Expand Up @@ -178,7 +178,7 @@ public function get(string $key)
{
try {
$result = $this->redis->get($key);
if ($this->redis instanceof \Predis\Client && $result === null) {
if ($this->redis instanceof \Predis\ClientInterface && $result === null) {
return false;
}
return $result;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Ackintosh\Ganesha\Storage\Adapter;

use Predis\ClientInterface;

class PredisRedisClientInterfaceTest extends PredisRedisTest
{
protected function getRedisConnection(): ClientInterface
{
return new PredisRedisClientInterfaceTestDouble(
parent::getRedisConnection()
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php
declare(strict_types=1);

namespace Ackintosh\Ganesha\Storage\Adapter;

use Predis\ClientInterface;
use Predis\Command\CommandInterface;

final class PredisRedisClientInterfaceTestDouble implements ClientInterface
{
/**
* @var ClientInterface
*/
private $client;

public function __construct(ClientInterface $client)
{
$this->client = $client;
}

/**
* {@inheritdoc}
*/
public function getProfile()
{
return $this->client->getProfile();
}

/**
* {@inheritdoc}
*/
public function getOptions()
{
return $this->client->getOptions();
}

/**
* {@inheritdoc}
*/
public function connect()
{
$this->client->connect();
}

/**
* {@inheritdoc}
*/
public function disconnect()
{
$this->client->disconnect();
}

/**
* {@inheritdoc}
*/
public function getConnection()
{
return $this->client->getConnection();
}

/**
* {@inheritdoc}
*/
public function createCommand($commandID, $arguments = [])
{
return $this->client->createCommand($commandID, $arguments);
}

/**
* {@inheritdoc}
*/
public function executeCommand(CommandInterface $command)
{
return $this->client->executeCommand($command);
}

/**
* {@inheritdoc}
*/
public function __call($commandID, $arguments)
{
return $this->executeCommand(
$this->createCommand($commandID, $arguments)
);
}
}
6 changes: 2 additions & 4 deletions tests/Ackintosh/Ganesha/Storage/Adapter/PredisRedisTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
namespace Ackintosh\Ganesha\Storage\Adapter;

use Predis\Client;
use Predis\ClientInterface;

class PredisRedisTest extends AbstractRedisTest
{
/**
* @return Client
*/
protected function getRedisConnection(): Client
protected function getRedisConnection(): ClientInterface
{
$r = new Client('tcp://' . (getenv('GANESHA_EXAMPLE_REDIS') ?: 'localhost'));
$r->connect();
Expand Down