diff --git a/Tests/Adapter/PredisReplicationAdapterTest.php b/Tests/Adapter/PredisReplicationAdapterTest.php index 28af1b5..b987723 100644 --- a/Tests/Adapter/PredisReplicationAdapterTest.php +++ b/Tests/Adapter/PredisReplicationAdapterTest.php @@ -27,9 +27,9 @@ public static function setUpBeforeClass(): void $hosts = explode(' ', getenv('REDIS_REPLICATION_HOSTS')); $lastArrayKey = array_key_last($hosts); $hostTable = []; - foreach($hosts as $key => $host) { + foreach ($hosts as $key => $host) { $hostInformation = array_combine(['host', 'port'], explode(':', $host)); - if($lastArrayKey === $key) { + if ($lastArrayKey === $key) { $hostInformation['role'] = 'master'; } $hostTable[] = $hostInformation; diff --git a/Tests/Traits/RedisProxiesTest.php b/Tests/Traits/RedisProxiesTest.php index 1e17b47..8896769 100644 --- a/Tests/Traits/RedisProxiesTest.php +++ b/Tests/Traits/RedisProxiesTest.php @@ -34,7 +34,7 @@ public function testRedisProxy($class) $expected = substr($proxy, 0, 2 + strpos($proxy, '}')); $methods = []; - foreach ((new \ReflectionClass(sprintf('Symfony\Component\Cache\Traits\\%s%dProxy', $class, $version)))->getMethods() as $method) { + foreach ((new \ReflectionClass(\sprintf('Symfony\Component\Cache\Traits\\%s%dProxy', $class, $version)))->getMethods() as $method) { if ('reset' === $method->name || method_exists(LazyProxyTrait::class, $method->name)) { continue; } @@ -87,12 +87,12 @@ public function testRelayProxy() $expectedMethods = []; foreach ((new \ReflectionClass(RelayProxy::class))->getMethods() as $method) { - if ('reset' === $method->name || method_exists(LazyProxyTrait::class, $method->name) || $method->isStatic()) { + if ('reset' === $method->name || method_exists(LazyProxyTrait::class, $method->name) || $method->isInternal()) { continue; } $return = '__construct' === $method->name || $method->getReturnType() instanceof \ReflectionNamedType && 'void' === (string) $method->getReturnType() ? '' : 'return '; - $expectedMethods[$method->name] = "\n ".ProxyHelper::exportSignature($method, false, $args)."\n".<<name] = "\n ".ProxyHelper::exportSignature($method, true, $args)."\n".<<initializeLazyObject()->{$method->name}({$args}); } @@ -101,7 +101,7 @@ public function testRelayProxy() } foreach ((new \ReflectionClass(Relay::class))->getMethods() as $method) { - if ('reset' === $method->name || method_exists(RedisProxyTrait::class, $method->name) || $method->isStatic()) { + if ('__destruct' === $method->name || 'reset' === $method->name || $method->isStatic()) { continue; } $return = '__construct' === $method->name || $method->getReturnType() instanceof \ReflectionNamedType && 'void' === (string) $method->getReturnType() ? '' : 'return '; diff --git a/Traits/RedisTrait.php b/Traits/RedisTrait.php index f6bb9bb..f4a5b87 100644 --- a/Traits/RedisTrait.php +++ b/Traits/RedisTrait.php @@ -440,7 +440,7 @@ protected function doFetch(array $ids): iterable $result = []; - if ($this->redis instanceof \Predis\ClientInterface && ($this->redis->getConnection() instanceof ClusterInterface || $this->redis->getConnection() instanceof Predis2ClusterInterface)) { + if (($this->redis instanceof \Predis\ClientInterface && ($this->redis->getConnection() instanceof ClusterInterface || $this->redis->getConnection() instanceof Predis2ClusterInterface)) || $this->redis instanceof RelayCluster) { $values = $this->pipeline(function () use ($ids) { foreach ($ids as $id) { yield 'get' => [$id]; diff --git a/Traits/Relay/BgsaveTrait.php b/Traits/Relay/BgsaveTrait.php index 367f82f..f5cddcb 100644 --- a/Traits/Relay/BgsaveTrait.php +++ b/Traits/Relay/BgsaveTrait.php @@ -19,7 +19,7 @@ trait BgsaveTrait { public function bgsave($arg = null): \Relay\Relay|bool { - return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->bgsave(...\func_get_args()); + return $this->initializeLazyObject()->bgsave(...\func_get_args()); } } } else { @@ -30,7 +30,7 @@ trait BgsaveTrait { public function bgsave($schedule = false): \Relay\Relay|bool { - return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->bgsave(...\func_get_args()); + return $this->initializeLazyObject()->bgsave(...\func_get_args()); } } } diff --git a/Traits/Relay/FtTrait.php b/Traits/Relay/FtTrait.php new file mode 100644 index 0000000..8accd79 --- /dev/null +++ b/Traits/Relay/FtTrait.php @@ -0,0 +1,132 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Cache\Traits\Relay; + +if (version_compare(phpversion('relay'), '0.9.0', '>=')) { + /** + * @internal + */ + trait FtTrait + { + public function ftAggregate($index, $query, $options = null): \Relay\Relay|array|false + { + return $this->initializeLazyObject()->ftAggregate(...\func_get_args()); + } + + public function ftAliasAdd($index, $alias): \Relay\Relay|bool + { + return $this->initializeLazyObject()->ftAliasAdd(...\func_get_args()); + } + + public function ftAliasDel($alias): \Relay\Relay|bool + { + return $this->initializeLazyObject()->ftAliasDel(...\func_get_args()); + } + + public function ftAliasUpdate($index, $alias): \Relay\Relay|bool + { + return $this->initializeLazyObject()->ftAliasUpdate(...\func_get_args()); + } + + public function ftAlter($index, $schema, $skipinitialscan = false): \Relay\Relay|bool + { + return $this->initializeLazyObject()->ftAlter(...\func_get_args()); + } + + public function ftConfig($operation, $option, $value = null): \Relay\Relay|array|bool + { + return $this->initializeLazyObject()->ftConfig(...\func_get_args()); + } + + public function ftCreate($index, $schema, $options = null): \Relay\Relay|bool + { + return $this->initializeLazyObject()->ftCreate(...\func_get_args()); + } + + public function ftCursor($operation, $index, $cursor, $options = null): \Relay\Relay|array|bool + { + return $this->initializeLazyObject()->ftCursor(...\func_get_args()); + } + + public function ftDictAdd($dict, $term, ...$other_terms): \Relay\Relay|false|int + { + return $this->initializeLazyObject()->ftDictAdd(...\func_get_args()); + } + + public function ftDictDel($dict, $term, ...$other_terms): \Relay\Relay|false|int + { + return $this->initializeLazyObject()->ftDictDel(...\func_get_args()); + } + + public function ftDictDump($dict): \Relay\Relay|array|false + { + return $this->initializeLazyObject()->ftDictDump(...\func_get_args()); + } + + public function ftDropIndex($index, $dd = false): \Relay\Relay|bool + { + return $this->initializeLazyObject()->ftDropIndex(...\func_get_args()); + } + + public function ftExplain($index, $query, $dialect = 0): \Relay\Relay|false|string + { + return $this->initializeLazyObject()->ftExplain(...\func_get_args()); + } + + public function ftExplainCli($index, $query, $dialect = 0): \Relay\Relay|array|false + { + return $this->initializeLazyObject()->ftExplainCli(...\func_get_args()); + } + + public function ftInfo($index): \Relay\Relay|array|false + { + return $this->initializeLazyObject()->ftInfo(...\func_get_args()); + } + + public function ftProfile($index, $command, $query, $limited = false): \Relay\Relay|array|false + { + return $this->initializeLazyObject()->ftProfile(...\func_get_args()); + } + + public function ftSearch($index, $query, $options = null): \Relay\Relay|array|false + { + return $this->initializeLazyObject()->ftSearch(...\func_get_args()); + } + + public function ftSpellCheck($index, $query, $options = null): \Relay\Relay|array|false + { + return $this->initializeLazyObject()->ftSpellCheck(...\func_get_args()); + } + + public function ftSynDump($index): \Relay\Relay|array|false + { + return $this->initializeLazyObject()->ftSynDump(...\func_get_args()); + } + + public function ftSynUpdate($index, $synonym, $term_or_terms, $skipinitialscan = false): \Relay\Relay|bool + { + return $this->initializeLazyObject()->ftSynUpdate(...\func_get_args()); + } + + public function ftTagVals($index, $tag): \Relay\Relay|array|false + { + return $this->initializeLazyObject()->ftTagVals(...\func_get_args()); + } + } +} else { + /** + * @internal + */ + trait FtTrait + { + } +} diff --git a/Traits/Relay/GetWithMetaTrait.php b/Traits/Relay/GetWithMetaTrait.php new file mode 100644 index 0000000..79a75ed --- /dev/null +++ b/Traits/Relay/GetWithMetaTrait.php @@ -0,0 +1,32 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Cache\Traits\Relay; + +if (version_compare(phpversion('relay'), '0.10.1', '>=')) { + /** + * @internal + */ + trait GetWithMetaTrait + { + public function getWithMeta($key): \Relay\Relay|array|false + { + return $this->initializeLazyObject()->getWithMeta(...\func_get_args()); + } + } +} else { + /** + * @internal + */ + trait GetWithMetaTrait + { + } +} diff --git a/Traits/Relay/IsTrackedTrait.php b/Traits/Relay/IsTrackedTrait.php new file mode 100644 index 0000000..2852080 --- /dev/null +++ b/Traits/Relay/IsTrackedTrait.php @@ -0,0 +1,32 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Cache\Traits\Relay; + +if (version_compare(phpversion('relay'), '0.11.1', '>=')) { + /** + * @internal + */ + trait IsTrackedTrait + { + public function isTracked($key): bool + { + return $this->initializeLazyObject()->isTracked(...\func_get_args()); + } + } +} else { + /** + * @internal + */ + trait IsTrackedTrait + { + } +} diff --git a/Traits/Relay/Relay11Trait.php b/Traits/Relay/Relay11Trait.php new file mode 100644 index 0000000..eeeeb45 --- /dev/null +++ b/Traits/Relay/Relay11Trait.php @@ -0,0 +1,132 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Cache\Traits\Relay; + +if (version_compare(phpversion('relay'), '0.11.0', '>=')) { + /** + * @internal + */ + trait Relay11Trait + { + public function cmsIncrBy($key, $field, $value, ...$fields_and_falues): \Relay\Relay|array|false + { + return $this->initializeLazyObject()->cmsIncrBy(...\func_get_args()); + } + + public function cmsInfo($key): \Relay\Relay|array|false + { + return $this->initializeLazyObject()->cmsInfo(...\func_get_args()); + } + + public function cmsInitByDim($key, $width, $depth): \Relay\Relay|bool + { + return $this->initializeLazyObject()->cmsInitByDim(...\func_get_args()); + } + + public function cmsInitByProb($key, $error, $probability): \Relay\Relay|bool + { + return $this->initializeLazyObject()->cmsInitByProb(...\func_get_args()); + } + + public function cmsMerge($dstkey, $keys, $weights = []): \Relay\Relay|bool + { + return $this->initializeLazyObject()->cmsMerge(...\func_get_args()); + } + + public function cmsQuery($key, ...$fields): \Relay\Relay|array|false + { + return $this->initializeLazyObject()->cmsQuery(...\func_get_args()); + } + + public function commandlog($subcmd, ...$args): \Relay\Relay|array|bool|int + { + return $this->initializeLazyObject()->commandlog(...\func_get_args()); + } + + public function hexpire($hash, $ttl, $fields, $mode = null): \Relay\Relay|array|false + { + return $this->initializeLazyObject()->hexpire(...\func_get_args()); + } + + public function hexpireat($hash, $ttl, $fields, $mode = null): \Relay\Relay|array|false + { + return $this->initializeLazyObject()->hexpireat(...\func_get_args()); + } + + public function hexpiretime($hash, $fields): \Relay\Relay|array|false + { + return $this->initializeLazyObject()->hexpiretime(...\func_get_args()); + } + + public function hgetdel($key, $fields): \Relay\Relay|array|false + { + return $this->initializeLazyObject()->hgetdel(...\func_get_args()); + } + + public function hgetex($hash, $fields, $expiry = null): \Relay\Relay|array|false + { + return $this->initializeLazyObject()->hgetex(...\func_get_args()); + } + + public function hpersist($hash, $fields): \Relay\Relay|array|false + { + return $this->initializeLazyObject()->hpersist(...\func_get_args()); + } + + public function hpexpire($hash, $ttl, $fields, $mode = null): \Relay\Relay|array|false + { + return $this->initializeLazyObject()->hpexpire(...\func_get_args()); + } + + public function hpexpireat($hash, $ttl, $fields, $mode = null): \Relay\Relay|array|false + { + return $this->initializeLazyObject()->hpexpireat(...\func_get_args()); + } + + public function hpexpiretime($hash, $fields): \Relay\Relay|array|false + { + return $this->initializeLazyObject()->hpexpiretime(...\func_get_args()); + } + + public function hpttl($hash, $fields): \Relay\Relay|array|false + { + return $this->initializeLazyObject()->hpttl(...\func_get_args()); + } + + public function hsetex($key, $fields, $expiry = null): \Relay\Relay|false|int + { + return $this->initializeLazyObject()->hsetex(...\func_get_args()); + } + + public function httl($hash, $fields): \Relay\Relay|array|false + { + return $this->initializeLazyObject()->httl(...\func_get_args()); + } + + public function serverName(): false|string + { + return $this->initializeLazyObject()->serverName(...\func_get_args()); + } + + public function serverVersion(): false|string + { + return $this->initializeLazyObject()->serverVersion(...\func_get_args()); + } + } +} else { + /** + * @internal + */ + trait Relay11Trait + { + } +} diff --git a/Traits/Relay/SwapdbTrait.php b/Traits/Relay/SwapdbTrait.php new file mode 100644 index 0000000..46cb2fe --- /dev/null +++ b/Traits/Relay/SwapdbTrait.php @@ -0,0 +1,32 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Cache\Traits\Relay; + +if (version_compare(phpversion('relay'), '0.9.0', '>=')) { + /** + * @internal + */ + trait SwapdbTrait + { + public function swapdb($index1, $index2): \Relay\Relay|bool + { + return $this->initializeLazyObject()->swapdb(...\func_get_args()); + } + } +} else { + /** + * @internal + */ + trait SwapdbTrait + { + } +} diff --git a/Traits/RelayProxy.php b/Traits/RelayProxy.php index b6d48dd..43b8956 100644 --- a/Traits/RelayProxy.php +++ b/Traits/RelayProxy.php @@ -13,12 +13,17 @@ use Symfony\Component\Cache\Traits\Relay\BgsaveTrait; use Symfony\Component\Cache\Traits\Relay\CopyTrait; +use Symfony\Component\Cache\Traits\Relay\FtTrait; use Symfony\Component\Cache\Traits\Relay\GeosearchTrait; use Symfony\Component\Cache\Traits\Relay\GetrangeTrait; +use Symfony\Component\Cache\Traits\Relay\GetWithMetaTrait; use Symfony\Component\Cache\Traits\Relay\HsetTrait; +use Symfony\Component\Cache\Traits\Relay\IsTrackedTrait; use Symfony\Component\Cache\Traits\Relay\MoveTrait; use Symfony\Component\Cache\Traits\Relay\NullableReturnTrait; use Symfony\Component\Cache\Traits\Relay\PfcountTrait; +use Symfony\Component\Cache\Traits\Relay\Relay11Trait; +use Symfony\Component\Cache\Traits\Relay\SwapdbTrait; use Symfony\Component\VarExporter\LazyObjectInterface; use Symfony\Contracts\Service\ResetInterface; @@ -34,9 +39,12 @@ class RelayProxy extends \Relay\Relay implements ResetInterface, LazyObjectInter { use BgsaveTrait; use CopyTrait; + use FtTrait; use GeosearchTrait; use GetrangeTrait; + use GetWithMetaTrait; use HsetTrait; + use IsTrackedTrait; use MoveTrait; use NullableReturnTrait; use PfcountTrait; @@ -44,6 +52,8 @@ class RelayProxy extends \Relay\Relay implements ResetInterface, LazyObjectInter resetLazyObject as reset; } use RelayProxyTrait; + use Relay11Trait; + use SwapdbTrait; public function __construct($host = null, $port = 6379, $connect_timeout = 0.0, $command_timeout = 0.0, #[\SensitiveParameter] $context = [], $database = 0) {