8000 Redis6ProxyTrait incompatible with PhpRedis 6.1.0 interface · Issue #58886 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
8000

Redis6ProxyTrait incompatible with PhpRedis 6.1.0 interface #58886

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

Closed
HMAZonderland opened this issue Nov 15, 2024 · 9 comments
Closed

Redis6ProxyTrait incompatible with PhpRedis 6.1.0 interface #58886

HMAZonderland opened this issue Nov 15, 2024 · 9 comments

Comments

@HMAZonderland
Copy link
HMAZonderland commented Nov 15, 2024

Symfony version(s) affected

All using phpredis 6.1 and Redis6ProxyTrait

Description

In the phpredis 6.1.0 release the interface for hset is defined as:

public function hSet(string $key, mixed ...$fields_and_vals): Redis|int|false;

The Redis6ProxyTrait trait implements this as:

public function hSet($key, ...$fields_and_vals): \Redis|false|int
{
    return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->hSet(...\func_get_args());
}

This triggers a Compile error:

Compile Error: Declaration of Symfony\Component\Cache\Traits\Redis6ProxyTrait::hSet($key, $fields_and_vals): Redis|int|false must be compatible with Redis::hSet(string $key, mixed ...$fields_and_vals): Redis|int|false

How to reproduce

  1. Install phpredis 6.1.0
  2. Call the hset function through a class that implemented the trait.

Possible Solution

Implement the phpredis interface correctly.

Additional Context

No response

@xabbuh
Copy link
Member
xabbuh commented Nov 15, 2024

Which version of the Cache component do you have installed?

8000

@HMAZonderland
Copy link
Author

This finding is from 6.4.11.

@HMAZonderland
Copy link
Author

This issue is mentioned in phpredis: phpredis/phpredis#2562

@stof
Copy link
Member
stof commented Nov 15, 2024

This is weird. 6.4.11 should be compatible with phpredis 6.1.0 as it includes the patch.

the signature in 6.4.11 is compatible with the Redis signature (removing the parameter types is fine, as widening parameter types in a child class is allowed).
However, the error message you are getting is suspicious because the signature it mentions does not match the Symfony source code.

Error message: Redis6ProxyTrait::hSet($key, $fields_and_vals): Redis|int|false
Source code: Redis6ProxyTrait::hSet($key, ...$fields_and_vals): Redis|int|false

For some reason, it looks like the second parameter is not variadic on the system in which you are getting the error. Please check that you are indeed using an unmodified 6.4.11 version.

@HMAZonderland
Copy link
Author
HMAZonderland commented Nov 15, 2024

Okay, I did some researching to make this reproducible:

Made this Docker file:

FROM php:8.2-cli

RUN apt-get update && apt-get install -y \
    unzip \
    libzip-dev \
    zip \
    && docker-php-ext-install zip

RUN apt-get update && apt-get install -y redis-server

RUN pecl install redis-6.1.0 \
    && docker-php-ext-enable redis

COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

WORKDIR /var/www/html

COPY composer.json composer.json
COPY example.php example.php

RUN composer install

EXPOSE 6379

CMD ["sh", "-c", "service redis-server start && php example.php"]

Include this composer.json

{
  "name": "phpredis/example",
  "require": {
    "php": "^8.2",
    "symfony/cache": "v6.4.11"
  },
  "autoload": {
    "psr-4": {
      "App\\": "src/"
    }
  }
}

Then include this example.php file:

<?php
declare(strict_types=1);

require 'vendor/autoload.php';

use Symfony\Component\Cache\Traits\Redis6Proxy;

$redisInstance = new Redis6Proxy();

$redisInstance->setKey('test_key', 'Hello, Redis with Redis6ProxyTrait!');
$value = $redisInstance->getKey('test_key');

var_dump($value);

Then build the container and run it:

% docker build -t phpredis-example .

Then run it:

% docker run --rm phpredis-example

Starting redis-server: redis-server.

Fatal error: Declaration of Symfony\Component\Cache\Traits\Redis6ProxyTrait::hSet($key, $fields_and_vals): Redis|int|false must be compatible with Redis::hSet(string $key, mixed ...$fields_and_vals): Redis|int|false in /var/www/html/vendor/symfony/cache/Traits/Redis6ProxyTrait.php on line 30

@stof
Copy link
Member
stof commented Nov 15, 2024

@HMAZonderland this does not work because COPY composer.json composer.json tries to copy a composer.json file that is not provided in your reproducer

@HMAZonderland
Copy link
Author
HMAZonderland commented Nov 15, 2024

@stof thanks! Noticed it was missing. I have included it now.

@stof
Copy link
Member
stof commented Nov 15, 2024

OK, found it. The link you shared for the Symfony source code was not for 6.4.11 but for the latest 6.4 branch. So the solution for this is simple: update to 6.4.12 or newer, where the issue is already fixed.

@stof stof closed this as not planned Won't fix, can't repro, duplicate, stale Nov 15, 2024
@HMAZonderland
Copy link
Author

Aha, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants
0