Skip to content

Use custom predis or phpredis implementation #729

@AntoineDewaele

Description

@AntoineDewaele

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions