-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Add support for REDIS_URL environment variables. #20891
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
Conversation
Can you add a test covering this ? |
@stof sure! Just a sec then |
That won't work: injecting a string (the REDIS_URL) in RedisAdapter is not allowed. |
I should review twice before posting :) So this forces any |
@nicolas-grekas what I am trying to understand is why the service definition you gave in the ticket; cache.default_redis_provider:
class: Redis
public: false
factory: ["Symfony\\Component\\Cache\\Adapter\\RedisAdapter", "createConnection"]
arguments:
- "%env(REDIS_URL)%" is different from this in PHP; $definition = new Definition(\Redis::class);
$definition->setPublic(false);
$definition->setFactory(array(RedisAdapter::class, 'createConnection'));
$definition->setArguments(array('%env(REDIS_URL)%'));
$container->setDefinition($name, $definition); This should do the same in the compilation process right? |
@nicolas-grekas ha you typed a response faster than I did. This approach worked in my application so I created this PR to get your opinion before putting any effort in the test cases. The |
When I apply your patch, I get the same:
The correct patch might be more like: --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CachePoolPass.php
+++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CachePoolPass.php
@@ -106,7 +106,9 @@ class CachePoolPass implements CompilerPassInterface
*/
public static function getServiceProvider(ContainerBuilder $container, $name)
{
- if (0 === strpos($name, 'redis://')) {
+ $container->resolveEnvPlaceholders($name, null, $usedEnvs);
+
+ if (0 === strpos($name, 'redis://') || $usedEnvs) {
$dsn = $name;
if (!$container->hasDefinition($name = md5($dsn))) { Btw, I'd be OK on my side to have this as bugfix on 3.2. |
@nicolas-grekas you are right, I was looking at the wrong thing. I've added the resolve call and updated the testcases to test both the default string and the env var. |
|
||
framework: | ||
cache: | ||
default_redis_provider: "%env(REDIS_URL)%" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing EOL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the EOL
👍 (on 3.2 also) |
Thank you @robinvdvleuten. |
…leuten) This PR was submitted for the master branch but it was merged into the 3.2 branch instead (closes #20891). Discussion ---------- Add support for REDIS_URL environment variables. | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #20850 | License | MIT | Doc PR | - In most PAAS solutions - Heroku for example - the Redis connection string is exposed as an environment variable like `REDIS_URL`. This PR adds support for those by allowing the following config; ```yml framework: cache: default_redis_provider: "%env(REDIS_URL)%" ``` In the referenced issue there was some discussion about maybe a new config options like `default_redis_url`, but this makes it hard to check in the extension for the case that an user configured a custom _default_redis_provider_ and also has configured the default url. Commits ------- 4e6086f Add support for REDIS_URL environment variables.
This is the fastest ever submitted+reviewed+fixed+merged+released PR :) |
@nicolas-grekas yes indeed! Thanks for all the time and effort you guys put into this process :) |
However, it seems that it breaks tests: https://travis-ci.org/symfony/symfony/jobs/183649383 |
Sorry, this isn't related: #20906 |
I do think it's related since the test only fails in its |
In most PAAS solutions - Heroku for example - the Redis connection string is exposed as an environment variable like
REDIS_URL
. This PR adds support for those by allowing the following config;In the referenced issue there was some discussion about maybe a new config options like
default_redis_url
, but this makes it hard to check in the extension for the case that an user configured a custom default_redis_provider and also has configured the default url.