Skip to content

Commit

Permalink
Merge pull request #13 from boesing/feature/redis-cluster
Browse files Browse the repository at this point in the history
Feature: redis cluster support
  • Loading branch information
boesing committed Jun 3, 2021
2 parents 8965bc7 + 3606b07 commit de8a63d
Show file tree
Hide file tree
Showing 32 changed files with 2,406 additions and 83 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ jobs:
ports:
- 6379:6379
options: --health-cmd="redis-cli ping" --health-interval=10s --health-timeout=5s --health-retries=3
redis-cluster:
image: vishnunair/docker-redis-cluster:latest
options: --health-cmd="redis-cli -c -p 6379 cluster nodes" --health-interval=10s --health-timeout=5s --health-retries=3
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.matrix.outputs.matrix) }}
Expand All @@ -39,3 +42,4 @@ jobs:
job: ${{ matrix.job }}
env:
TESTS_LAMINAS_CACHE_REDIS_HOST: redis
TESTS_LAMINAS_CACHE_REDIS_CLUSTER_NAME: cluster
8 changes: 7 additions & 1 deletion .laminas-ci.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
{
"extensions": [
"redis"
"redis",
"igbinary"
],
"ini": [
"redis.clusters.seeds = 'cluster[]=redis-cluster:6379&cluster[]=redis-cluster:6380&cluster[]=redis-cluster:6381&cluster[]=redis-cluster:6382&cluster[]=redis-cluster:6383&cluster[]=redis-cluster:6384'",
"redis.clusters.timeout = 'cluster=5'",
"redis.clusters.read_timeout = 'cluster=10'"
]
}
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"laminas/laminas-cache-storage-implementation": "1.0"
},
"require-dev": {
"ext-posix": "*",
"ext-redis": "*",
"composer-runtime-api": "^2",
"laminas/laminas-cache": "^2.10",
Expand All @@ -37,7 +38,8 @@
"autoload-dev": {
"psr-4": {
"LaminasTest\\Cache\\Storage\\Adapter\\": "test/unit",
"LaminasTest\\Cache\\Psr\\": "test/integration/Psr"
"LaminasTest\\Cache\\Psr\\": "test/integration/Psr",
"LaminasTest\\Cache\\Storage\\Adapter\\Laminas\\": "test/integration/Laminas"
}
},
"scripts": {
Expand Down
3 changes: 2 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 1 addition & 23 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
<code>$ttl</code>
<code>$ttl</code>
</InvalidScalarArgument>
<InvalidThrow occurrences="1">
<code>Exception\ExceptionInterface</code>
</InvalidThrow>
<LessSpecificReturnStatement occurrences="1">
<code>parent::setOptions($options)</code>
</LessSpecificReturnStatement>
Expand Down Expand Up @@ -283,25 +280,6 @@
<code>$info</code>
</UnusedVariable>
</file>
<file src="test/integration/Psr/CacheItemPool/RedisIntegrationTest.php">
<MixedArrayAssignment occurrences="1">
<code>$this-&gt;skippedTests['testHasItemReturnsFalseWhenDeferredItemIsExpired']</code>
</MixedArrayAssignment>
<RedundantConditionGivenDocblockType occurrences="1">
<code>$this-&gt;storage</code>
</RedundantConditionGivenDocblockType>
<UndefinedInterfaceMethod occurrences="1">
<code>addPlugin</code>
</UndefinedInterfaceMethod>
</file>
<file src="test/integration/Psr/SimpleCache/RedisIntegrationTest.php">
<RedundantConditionGivenDocblockType occurrences="1">
<code>$this-&gt;storage</code>
</RedundantConditionGivenDocblockType>
<UndefinedInterfaceMethod occurrences="1">
<code>addPlugin</code>
</UndefinedInterfaceMethod>
</file>
<file src="test/unit/RedisResourceManagerTest.php">
<ArgumentTypeCoercion occurrences="2">
<code>'Redis'</code>
Expand All @@ -317,7 +295,7 @@
<code>testValidPersistentId</code>
</MissingReturnType>
</file>
<file src="test/unit/RedisTest.php">
<file src="test/integration/Laminas/RedisTest.php">
<MissingReturnType occurrences="23">
<code>testGetCapabilitiesTtl</code>
<code>testGetSetDatabase</code>
Expand Down
14 changes: 13 additions & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
errorBaseline="psalm-baseline.xml"
errorBaseline="psalm-baseline.xml"
>
<projectFiles>
<directory name="src"/>
Expand All @@ -14,6 +14,18 @@
<directory name="vendor"/>
</ignoreFiles>
</projectFiles>
<issueHandlers>
<InvalidThrow>
<errorLevel type="suppress">
<referencedClass name="Laminas\Cache\Exception\ExceptionInterface"/>
</errorLevel>
</InvalidThrow>
<InternalMethod>
<errorLevel type="suppress">
<referencedMethod name="Laminas\Cache\Storage\Adapter\RedisClusterOptions::setResourceManager"/>
</errorLevel>
</InternalMethod>
</issueHandlers>
<plugins>
<pluginClass class="Psalm\PhpUnitPlugin\Plugin"/>
</plugins>
Expand Down
45 changes: 45 additions & 0 deletions src/Exception/InvalidRedisClusterConfigurationException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

namespace Laminas\Cache\Storage\Adapter\Exception;

use Laminas\Cache\Exception\InvalidArgumentException;

use function sprintf;

final class InvalidRedisClusterConfigurationException extends InvalidArgumentException
{
public static function fromMissingSeedsConfiguration(): self
{
return new self('Could not find `redis.clusters.seeds` entry in the php.ini file(s).');
}

public static function fromMissingSeedsForNamedConfiguration(string $name): self
{
return new self(sprintf(
'Missing `%s` within the configured `redis.cluster.seeds` entry in the php.ini file(s).',
$name
));
}

public static function fromMissingRequiredValues(): self
{
return new self('Missing either `name` or `seeds`.');
}

public static function fromNameAndSeedsProvidedViaConfiguration(): self
{
return new self('Please provide either `name` or `seeds` configuration, not both.');
}

public static function fromInvalidSeedsConfiguration(string $seed): self
{
return new self(
sprintf(
'Configured `seed` %s is invalid. Must be configured as "host:port" while separated by a colon.',
$seed
)
);
}
}
14 changes: 14 additions & 0 deletions src/Exception/MetadataErrorException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace Laminas\Cache\Storage\Adapter\Exception;

use Laminas\Cache\Exception\RuntimeException;

/**
* @internal
*/
final class MetadataErrorException extends RuntimeException
{
}
29 changes: 29 additions & 0 deletions src/Exception/RedisRuntimeException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace Laminas\Cache\Storage\Adapter\Exception;

use Laminas\Cache\Exception\RuntimeException as LaminasCacheRuntimeException;
use RedisCluster;
use RedisClusterException;
use Throwable;

final class RedisRuntimeException extends LaminasCacheRuntimeException
{
public static function fromClusterException(RedisClusterException $exception, RedisCluster $redis): self
{
$message = $redis->getLastError() ?? $exception->getMessage();

return new self($message, (int) $exception->getCode(), $exception);
}

public static function fromFailedConnection(Throwable $exception): self
{
return new self(
'Could not establish connection',
(int) $exception->getCode(),
$exception
);
}
}
Loading

0 comments on commit de8a63d

Please sign in to comment.