Skip to content

Use universal interface for Redis, or remove @internal from RedisProxy #42428

Closed
@sirian

Description

@sirian

Description

At this moment all of Symfony Redis adapters/handlers tightly bound to \Redis | \RedisArray | \RedisCluster | RedisProxy | RedisClusterProxy | \Predis\ClientInterface

Symfony\Component\Lock\Store\RedisStore
Symfony\Component\Cache\Adapter\RedisAdapter
Symfony\Component\HttpFoundation\Session\Storage\Handler\RedisSessionHandler

I want to log/profile redis commands (phpredis), but there is no right way to use decorated Redis class with Symfony components.

  • Attempt 1 - Simple decoration - won't bypass instanceof checks inside Symfony classes.
/** @mixin Redis */
class RedisClient
{
    public function __construct(
        private Redis $redis;
        private LoggerInterface $logger;
    ) {}

    public function call(string $name, array $arguments)
    {
            $this->logger->debug('...');
            return $this->redis->{$name}(...$arguments);
    }
}

new Symfony\Component\Lock\Store\RedisStore(new RedisClient(...)); // throws InvalidArgumentException
  • Attempt 2 - extend \Redis
    This requires to override all Redis methods and this is ridiculous. Look at this 1500+ lines example:
    https://github.com/snc/SncRedisBundle/blob/d7718cd75166bb256380cf428cbde54402be149e/Client/Phpredis/Client.php#L189

  • Attempt 3 (dirty) - extend Symfony\Component\Cache\Traits\RedisProxy.
    This works, but RedisProxy marked as @internal so you will get deprecation errors. And since it's internal - there is no guarantee that this class will not be silently changed.

  • Attempt 4 (dirty+monkeypatching) - copy RedisProxy to src. Configure autoload and exclude-from-classmap in composer.json. But let's leave monkeypatching for javascript community!

Final thoughts
Please either remove @internal from Symfony\Component\Cache\Traits\RedisProxy or add another way to solve this problem

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions