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

Use custom predis or phpredis implementation #729

Open
AntoineDewaele opened this issue Oct 28, 2024 · 0 comments
Open

Use custom predis or phpredis implementation #729

AntoineDewaele opened this issue Oct 28, 2024 · 0 comments

Comments

@AntoineDewaele
Copy link

Hello guys,

I've been dealing with an issue with the bundle configuration. I'm trying to implement a custom implementation of predis connection to override the replication strategy.

But i didn't find any way to use a custom connection through the bundle config. It only allows predis or phpredis type in extension :

  switch ($client['type']) {
      case 'predis':
          $this->loadPredisClient($client, $container);
          break;
      case 'phpredis':
          $this->loadPhpredisClient($client, $container);
          break;
      default:
          throw new \InvalidArgumentException(sprintf('The redis client type %s is invalid.', $client['type']));
          break;
  }

The only way i found to do this is to override the container after the bundle config file parsing with a compiler pass, but i find it more convenient to do this on the config file :

class SncRedisCompilerPass implements CompilerPassInterface
{
    public function process(ContainerBuilder $container)
    {
        $sncRedisDefinition = $container->getDefinition('snc_redis.session');
        $sncRedisDefinition->setClass('App\CustomRedisConnection');
        $container->setDefinition('snc_redis.session', $sncRedisDefinition);

        $sncRedisDefinition = $container->getDefinition('snc_redis.default');
        $sncRedisDefinition->setClass('App\CustomRedisConnection');
        $container->setDefinition('snc_redis.default', $sncRedisDefinition);
    }
}

Maybe with a new param in the config file ?

I can make a pull request for this, but i firstly wanted to know if i didn't miss something and if this is a good way for you.

Thanks.

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

No branches or pull requests

1 participant