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

Add support for ext-redis v6.0 #79

Merged
merged 5 commits into from
Sep 13, 2023
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: 10 additions & 0 deletions .laminas-ci.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,15 @@
"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'"
],
"additional_checks": [
{
"name": "Run tests on ext-redis 5.3.7",
"job": {
"php": "*",
"dependencies": "locked",
"command": "REDIS_VERSION=5.3.7 vendor/bin/phpunit"
}
}
]
}
12 changes: 12 additions & 0 deletions .laminas-ci/pre-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

JOB=$3

COMMAND=$(echo "${JOB}" | jq -r '.command // ""')
[[ "${COMMAND}" =~ ^REDIS_VERSION=([0-9\.]+) ]] || exit 0

PHP=$(echo "${JOB}" | jq -r '.php // ""')
REDIS_VERSION=${BASH_REMATCH[1]}

pecl install -f --configureoptions 'enable-redis-igbinary="yes" enable-redis-lzf="yes"' igbinary redis-${REDIS_VERSION}
echo "extension=redis.so" > /etc/php/${PHP}/mods-available/redis.ini
4 changes: 2 additions & 2 deletions benchmark/RedisClusterStorageAdapterBench.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use PhpBench\Benchmark\Metadata\Annotations\Iterations;
use PhpBench\Benchmark\Metadata\Annotations\Revs;
use PhpBench\Benchmark\Metadata\Annotations\Warmup;
use RedisCluster;
use Redis;

/**
* @Revs(100)
Expand All @@ -23,7 +23,7 @@ class RedisClusterStorageAdapterBench extends AbstractStorageAdapterBenchmark
public function __construct()
{
parent::__construct($this->createRedisClusterStorage(
RedisCluster::SERIALIZER_NONE,
Redis::SERIALIZER_NONE,
true
));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use PhpBench\Benchmark\Metadata\Annotations\Iterations;
use PhpBench\Benchmark\Metadata\Annotations\Revs;
use PhpBench\Benchmark\Metadata\Annotations\Warmup;
use RedisCluster;
use Redis;

/**
* @Revs(100)
Expand All @@ -23,7 +23,7 @@ class RedisClusterWithIgbinarySerializerStorageAdapterBench extends AbstractStor
public function __construct()
{
parent::__construct($this->createRedisClusterStorage(
RedisCluster::SERIALIZER_IGBINARY,
Redis::SERIALIZER_IGBINARY,
false
));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use PhpBench\Benchmark\Metadata\Annotations\Iterations;
use PhpBench\Benchmark\Metadata\Annotations\Revs;
use PhpBench\Benchmark\Metadata\Annotations\Warmup;
use RedisCluster;
use Redis;

/**
* @Revs(100)
Expand All @@ -23,7 +23,7 @@ class RedisClusterWithPhpSerializerStorageAdapterBench extends AbstractStorageAd
public function __construct()
{
parent::__construct($this->createRedisClusterStorage(
RedisCluster::SERIALIZER_PHP,
Redis::SERIALIZER_PHP,
false
));
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"license": "BSD-3-Clause",
"require": {
"php": "~8.0.0 || ~8.1.0 || ~8.2.0",
"ext-redis": "^4.3 || ^5.0.2",
"ext-redis": "^5.0.2 || ^6.0",
"laminas/laminas-cache": "^3.0"
},
"provide": {
Expand Down
4 changes: 2 additions & 2 deletions composer.lock

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

10 changes: 5 additions & 5 deletions src/RedisCluster.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Laminas\Cache\Storage\ClearByNamespaceInterface;
use Laminas\Cache\Storage\ClearByPrefixInterface;
use Laminas\Cache\Storage\FlushableInterface;
use Redis;
use Redis as RedisFromExtension;
use RedisCluster as RedisClusterFromExtension;
use RedisClusterException;
use RedisException;
Expand Down Expand Up @@ -76,7 +76,7 @@ public function setOptions($options)
* In RedisCluster, it is totally okay if just one primary server is being flushed.
* If one or more primaries are not reachable, they will re-sync if they're coming back online.
*
* One has to connect to the primaries directly using {@see Redis::connect}.
* One has to connect to the primaries directly using {@see RedisFromExtension::connect}.
*/
public function flush(): bool
{
Expand All @@ -86,7 +86,7 @@ public function flush(): bool
$masters = $resource->_masters();

foreach ($masters as [$host, $port]) {
$redis = new Redis();
$redis = new RedisFromExtension();
try {
$redis->connect($host, $port);
} catch (RedisException $exception) {
Expand Down Expand Up @@ -436,8 +436,8 @@ private function clusterException(
*/
private function isFalseReturnValuePersisted(RedisClusterFromExtension $redis, string $key): bool
{
$serializer = $this->getLibOption(RedisClusterFromExtension::OPT_SERIALIZER);
if ($serializer === RedisClusterFromExtension::SERIALIZER_NONE) {
$serializer = $this->getLibOption(RedisFromExtension::OPT_SERIALIZER);
if ($serializer === RedisFromExtension::SERIALIZER_NONE) {
return false;
}

Expand Down
7 changes: 4 additions & 3 deletions src/RedisClusterResourceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Laminas\Cache\Storage\Plugin\PluginInterface;
use Laminas\Cache\Storage\Plugin\Serializer;
use Laminas\Cache\Storage\PluginCapableInterface;
use Redis as RedisFromExtension;
use RedisCluster as RedisClusterFromExtension;
use RedisClusterException;

Expand Down Expand Up @@ -185,11 +186,11 @@ public function hasSerializationSupport(PluginCapableInterface $adapter): bool
*/
$options = $this->options;
$serializer = $options->getLibOption(
RedisClusterFromExtension::OPT_SERIALIZER,
RedisClusterFromExtension::SERIALIZER_NONE
RedisFromExtension::OPT_SERIALIZER,
RedisFromExtension::SERIALIZER_NONE
);

if ($serializer !== RedisClusterFromExtension::SERIALIZER_NONE) {
if ($serializer !== RedisFromExtension::SERIALIZER_NONE) {
return true;
}

Expand Down
6 changes: 3 additions & 3 deletions test/integration/Laminas/RedisClusterStorageCreationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Laminas\Cache\Storage\Adapter\RedisCluster;
use Laminas\Cache\Storage\Adapter\RedisClusterOptions;
use Laminas\Cache\Storage\Plugin\Serializer;
use RedisCluster as RedisClusterFromExtension;
use Redis as RedisFromExtension;
use RuntimeException;

use function implode;
Expand Down Expand Up @@ -44,13 +44,13 @@ private function createRedisClusterStorage(int $serializerOption, bool $serializ
$this->options = new RedisClusterOptions([
'name' => $node,
'lib_options' => [
RedisClusterFromExtension::OPT_SERIALIZER => $serializerOption,
RedisFromExtension::OPT_SERIALIZER => $serializerOption,
],
'namespace' => str_shuffle(implode('', ['a', 'b', 'c', 'd', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'])),
]);

$storage = new RedisCluster($this->options);
if ($serializerOption === RedisClusterFromExtension::SERIALIZER_NONE && $serializerPlugin) {
if ($serializerOption === RedisFromExtension::SERIALIZER_NONE && $serializerPlugin) {
$storage->addPlugin(new Serializer());
}

Expand Down
8 changes: 4 additions & 4 deletions test/integration/Laminas/RedisClusterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Laminas\Cache\Storage\Plugin\Serializer;
use Laminas\Cache\Storage\StorageInterface;
use LaminasTest\Cache\Storage\Adapter\AbstractCommonAdapterTest;
use RedisCluster as RedisClusterFromExtension;
use Redis as RedisFromExtension;

/**
* @template-extends AbstractCommonAdapterTest<RedisCluster,RedisClusterOptions>
Expand Down Expand Up @@ -51,7 +51,7 @@ public function testWillHandleIntegratedSerializerInformation(): void

$options = $storage->getOptions();
$options->setLibOptions([
RedisClusterFromExtension::OPT_SERIALIZER => RedisClusterFromExtension::SERIALIZER_PHP,
RedisFromExtension::OPT_SERIALIZER => RedisFromExtension::SERIALIZER_PHP,
]);

$capabilities = $storage->getCapabilities();
Expand Down Expand Up @@ -86,7 +86,7 @@ public function testWillHandleNonSupportedSerializerInformation(): void
$this->removeSerializer($storage);
$options = $storage->getOptions();
$options->setLibOptions([
RedisClusterFromExtension::OPT_SERIALIZER => RedisClusterFromExtension::SERIALIZER_NONE,
RedisFromExtension::OPT_SERIALIZER => RedisFromExtension::SERIALIZER_NONE,
]);

$capabilities = $storage->getCapabilities();
Expand Down Expand Up @@ -136,7 +136,7 @@ public function testClearsByNamespace(): void
protected function setUp(): void
{
$this->storage = $this->createRedisClusterStorage(
RedisClusterFromExtension::SERIALIZER_PHP,
RedisFromExtension::SERIALIZER_PHP,
false
);
// Clear storage before executing tests.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Laminas\Cache\Storage\StorageInterface;
use LaminasTest\Cache\Storage\Adapter\AbstractCacheItemPoolIntegrationTest;
use LaminasTest\Cache\Storage\Adapter\Laminas\RedisClusterStorageCreationTrait;
use Redis;
use RedisCluster;

use function sprintf;
Expand All @@ -26,6 +27,6 @@ protected function setUp(): void

protected function createStorage(): StorageInterface
{
return $this->createRedisClusterStorage(RedisCluster::SERIALIZER_IGBINARY, false);
return $this->createRedisClusterStorage(Redis::SERIALIZER_IGBINARY, false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Laminas\Cache\Storage\StorageInterface;
use LaminasTest\Cache\Storage\Adapter\AbstractCacheItemPoolIntegrationTest;
use LaminasTest\Cache\Storage\Adapter\Laminas\RedisClusterStorageCreationTrait;
use Redis;
use RedisCluster;

use function sprintf;
Expand All @@ -26,6 +27,6 @@ protected function setUp(): void

protected function createStorage(): StorageInterface
{
return $this->createRedisClusterStorage(RedisCluster::SERIALIZER_PHP, false);
return $this->createRedisClusterStorage(Redis::SERIALIZER_PHP, false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Laminas\Cache\Storage\StorageInterface;
use LaminasTest\Cache\Storage\Adapter\AbstractCacheItemPoolIntegrationTest;
use LaminasTest\Cache\Storage\Adapter\Laminas\RedisClusterStorageCreationTrait;
use Redis;
use RedisCluster;

use function sprintf;
Expand All @@ -26,6 +27,6 @@ protected function setUp(): void

protected function createStorage(): StorageInterface
{
return $this->createRedisClusterStorage(RedisCluster::SERIALIZER_NONE, true);
return $this->createRedisClusterStorage(Redis::SERIALIZER_NONE, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
use Laminas\Cache\Storage\StorageInterface;
use LaminasTest\Cache\Storage\Adapter\AbstractSimpleCacheIntegrationTest;
use LaminasTest\Cache\Storage\Adapter\Laminas\RedisClusterStorageCreationTrait;
use RedisCluster;
use Redis;

final class RedisClusterWithPhpIgbinaryTest extends AbstractSimpleCacheIntegrationTest
{
use RedisClusterStorageCreationTrait;

protected function createStorage(): StorageInterface
{
return $this->createRedisClusterStorage(RedisCluster::SERIALIZER_IGBINARY, false);
return $this->createRedisClusterStorage(Redis::SERIALIZER_IGBINARY, false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
use Laminas\Cache\Storage\StorageInterface;
use LaminasTest\Cache\Storage\Adapter\AbstractSimpleCacheIntegrationTest;
use LaminasTest\Cache\Storage\Adapter\Laminas\RedisClusterStorageCreationTrait;
use RedisCluster;
use Redis;

final class RedisClusterWithPhpSerializerTest extends AbstractSimpleCacheIntegrationTest
{
use RedisClusterStorageCreationTrait;

protected function createStorage(): StorageInterface
{
return $this->createRedisClusterStorage(RedisCluster::SERIALIZER_PHP, false);
return $this->createRedisClusterStorage(Redis::SERIALIZER_PHP, false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
use Laminas\Cache\Storage\StorageInterface;
use LaminasTest\Cache\Storage\Adapter\AbstractSimpleCacheIntegrationTest;
use LaminasTest\Cache\Storage\Adapter\Laminas\RedisClusterStorageCreationTrait;
use RedisCluster;
use Redis;

final class RedisClusterWithoutSerializerTest extends AbstractSimpleCacheIntegrationTest
{
use RedisClusterStorageCreationTrait;

protected function createStorage(): StorageInterface
{
return $this->createRedisClusterStorage(RedisCluster::SERIALIZER_NONE, true);
return $this->createRedisClusterStorage(Redis::SERIALIZER_NONE, true);
}
}
4 changes: 2 additions & 2 deletions test/unit/RedisClusterOptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Laminas\Cache\Storage\Adapter\AdapterOptions;
use Laminas\Cache\Storage\Adapter\Exception\InvalidRedisClusterConfigurationException;
use Laminas\Cache\Storage\Adapter\RedisClusterOptions;
use RedisCluster as RedisClusterFromExtension;
use Redis as RedisFromExtension;
use ReflectionClass;

use function assert;
Expand Down Expand Up @@ -136,7 +136,7 @@ public function testOptionConstantsMatchingExtensionImplementation(string $const
*/
public function redisClusterOptionConstants(): Generator
{
$reflection = new ReflectionClass(RedisClusterFromExtension::class);
$reflection = new ReflectionClass(RedisFromExtension::class);

foreach ($reflection->getConstants() as $constant => $constantValue) {
if (strpos($constant, 'OPT_') !== 0) {
Expand Down
6 changes: 3 additions & 3 deletions test/unit/RedisClusterResourceManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Laminas\Cache\Storage\Adapter\RedisClusterResourceManager;
use Laminas\Cache\Storage\Plugin\Serializer;
use PHPUnit\Framework\TestCase;
use RedisCluster;
use Redis;
use SplObjectStorage;

use function uniqid;
Expand Down Expand Up @@ -76,15 +76,15 @@ public function serializationSupportOptionsProvider(): array
new RedisClusterOptions([
'name' => uniqid('', true),
'lib_options' => [
RedisCluster::OPT_SERIALIZER => RedisCluster::SERIALIZER_PHP,
Redis::OPT_SERIALIZER => Redis::SERIALIZER_PHP,
],
]),
],
'igbinary-serialize' => [
new RedisClusterOptions([
'name' => uniqid('', true),
'lib_options' => [
RedisCluster::OPT_SERIALIZER => RedisCluster::SERIALIZER_IGBINARY,
Redis::OPT_SERIALIZER => Redis::SERIALIZER_IGBINARY,
],
]),
],
Expand Down
Loading