Skip to content

Commit

Permalink
Enable Lazy service for phpredis (#440)
Browse files Browse the repository at this point in the history
The service will be lazy if symfony/proxy-manager-bridge is installed
As a consequence it will allow to warmup the cache even if Redis server is not reachable

fix #434
  • Loading branch information
B-Galati authored and curry684 committed Jul 18, 2018
1 parent 3f3c233 commit a2d0faa
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions DependencyInjection/SncRedisExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ protected function loadPhpredisClient(array $client, ContainerBuilder $container
$phpredisDef->addArgument($client['alias']);
$phpredisDef->addTag('snc_redis.client', array('alias' => $client['alias']));
$phpredisDef->setPublic(false);
$phpredisDef->setLazy(true);

$container->setDefinition($phpredisId, $phpredisDef);
$container->setAlias(sprintf('snc_redis.%s', $client['alias']), new Alias($phpredisId, true));
Expand Down
11 changes: 11 additions & 0 deletions Resources/doc/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -386,3 +386,14 @@ snc_redis:
client: profiler_storage
ttl: 3600
```

## Troubleshooting ##

If cache warmup fails for prod because a redis server is not available,
try to install [`symfony/proxy-manager-bridge`](https://symfony.com/doc/master/service_container/lazy_services.html):

``` bash
$ composer require symfony/proxy-manager-bridge
```

Once done some services will be lazy-loaded and could prevent unwanted connection call.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"suggest": {
"monolog/monolog": "If you want to use the monolog redis handler.",
"predis/predis": "If you want to use predis.",
"symfony/console": "If you want to use commands to interact with the redis database"
"symfony/console": "If you want to use commands to interact with the redis database",
"symfony/proxy-manager-bridge": "If you want to lazy-load some services"
},
"autoload": {
"psr-4": { "Snc\\RedisBundle\\": "" }
Expand Down

0 comments on commit a2d0faa

Please sign in to comment.