I have the following settings for custom provider
services.yaml
app.my_custom_redis_provider:
class: Predis\Client
factory: [ 'Symfony\Component\Cache\Adapter\RedisAdapter', 'createConnection' ]
arguments:
- '%env(REDIS_URL)%'
- { retry_interval: 2, timeout: 10 }
cache.yaml
framework:
cache:
pools:
cache.my_redis:
adapter: cache.adapter.redis
provider: app.my_custom_redis_provider
I am not sure how to use that in my controller class as a service. When I do like this, it doesn't work
/**
* @Route("/predis/client", name="test_redis_client")
*/
public function testRedisClient(Predis\Client $cache)
{
}
When I map it to a class, it doesn't work either
<?php
namespace App\Client;
use Predis\Client;
class MyCustomRedisProvider
{
public function __construct(Client $client){
}
}
services.yaml
redis_cache:
class: App\Client\MyCustomRedisProvider
arguments: ['@app.my_custom_redis_provider']
THE WAY ONLY WORKS
However, when I use it plainly inside a Controller function it works
$client = RedisAdapter::createConnection(
$this->getParameter('redis_url'),
[
'persistent' => 1,
'timeout' => 20,
'ssl' => true
]
);
But I don't wanna do like above.
Do I need an extra class to map it on services to use the custom provider?