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

#428 #356 Fix support for DSN env variable with phpredis #432

Merged
merged 1 commit into from
Jun 25, 2018

Conversation

B-Galati
Copy link
Collaborator

@B-Galati B-Galati commented Jun 3, 2018

fix #428 #356

Basically the client is always instantiated at runtime thanks to PhpredisClientFactory class.

@B-Galati
Copy link
Collaborator Author

B-Galati commented Jun 3, 2018

Hello @fpondepeyre @Ensaerel @tgalopin @romain-pierre,

I would be glad if you can try it out on your setup :-)

@fpondepeyre
Copy link

fpondepeyre commented Jun 6, 2018

sorry but I don't know how to checkout this PR in my project... @B-Galati

@ghost
Copy link

ghost commented Jun 6, 2018

You can add:

"repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/B-Galati/SncRedisBundle.git"
        }
    ]

And target to the branch as "snc/redis-bundle": "dev-fix-428-356", then, do composer update snc/redis-bundle

@ghost
Copy link

ghost commented Jun 6, 2018

@B-Galati LGTM, but I can't confirm that the placeholder is correctly handled after the cache is built. Because in my environment, the vars are available and stay the same before and after the cache build.

@fpondepeyre
Copy link

it's seem work perfectly, no errors...

@B-Galati
Copy link
Collaborator Author

B-Galati commented Jun 6, 2018

Thanks for the feedback @fpondepeyre @romain-pierre

@B-Galati B-Galati force-pushed the fix-428-356 branch 2 times, most recently from e5b56a5 to 93f5c76 Compare June 16, 2018 06:36
@B-Galati
Copy link
Collaborator Author

Waiting for symfony/symfony#27470 to be released.

@B-Galati
Copy link
Collaborator Author

Once released the CI should be green.

@B-Galati B-Galati changed the title Fix support for DSN env variable with phpredis #428 #356 Fix support for DSN env variable with phpredis Jun 17, 2018
@curry684
Copy link
Collaborator

I'll merge this when Symfony 4.1.1 is out and look into the other PRs.

@curry684 curry684 self-assigned this Jun 18, 2018
@curry684 curry684 added the on-hold Will not be merged or solved until other tasks have been performed label Jun 19, 2018
@B-Galati
Copy link
Collaborator Author

The CI looks good now :D

@curry684 curry684 merged commit 9bb9dd6 into snc:2.1 Jun 25, 2018
@jhonnynho
Copy link

This changes are available in 2.x-dev?
Because I have the error setting the envs vars on snc_redis.yml on SYmfony 4.1.1

@curry684
Copy link
Collaborator

Both on 2.x-dev and 2.1.4 yes. What error are you seeing?

@jhonnynho
Copy link

jhonnynho commented Jun 26, 2018

I get this error

php_network_getaddresses: getaddrinfo failed: Name does not resolve [tcp://:6379]

I Have this config on my snc_redis.yml

snc_redis:
    clients:
        default:
            type: predis
            alias: default
            dsn:"redis://%env(REDIS_HOST)%:%env(REDIS_PORT)%/%env(REDIS_DBIDX)%"
            logging: "%kernel.debug%"

Symfony 4.1.1

@jhonnynho
Copy link

I dont get that error updating to 3.x-dev, but I don't know if exists a major changes between 2.1.x-dev and 3.x-dev

In the 2.1.x-dev version the error dissapear if only add in the dns param = %env(REDIS_HOST)% , only that.

That have sense for you? @curry684

@B-Galati
Copy link
Collaborator Author

@jhonnynho @curry684 I was able to reproduce the issue. It happens when using a specific a path within the DSN, e.g. /%env(REDIS_DBIDX)% for the given example. It looks like this "path" should match a database index.

I also noticed that if the path is numeric, everything is working as expected but otherwise it's not. It seems to be a normal behavior considering the fact that database index can only be an integer. Please let me know if I am wrong.

@jhonnynho Can you give us an example of what you are using as values ?

It looks like it was working in 2.1.3 but I think the value was just removed by the predis parser (we are not using that method anymore). https://github.com/nrk/predis/blob/111d100ee389d624036b46b35ed0c9ac59c71313/src/Connection/Parameters.php#L123

As per 2.1.4, both phpredis and predis DSN are parsed by RedisDsn class.

I guess we could improve DX by throwing any kind of error message when such a case is happening (e.g. string in path instead of an integer)

@curry684
Copy link
Collaborator

Nice work @B-Galati, thanks for all your efforts 😄

If this is indeed the case we should just treat it as a DX issue and improve the error, agreed.

@curry684
Copy link
Collaborator

Btw I didn't merge the 2.1.4 fixes into master yet so it's correct that 3.x-dev still has the old (wrong) behavior.

@jhonnynho
Copy link

Hi @B-Galati and @curry684

Here an example of the values that I have in my env

REDIS_HOST=redis
REDIS_PORT=6379
REDIS_DBIDX=tokens

To the DBIDX could be a string value, not necessary a integer, you can use both on Redis.

For now I'm use the version 2.1.3 on my project, works as expected.

I'll be waiting some news about this. Best.

@B-Galati
Copy link
Collaborator Author

@jhonnynho Thank you. I just tried with a 3.2 instance and got the following error.

root@49ac88ca7322:/data# redis-cli
127.0.0.1:6379> select 0
OK
127.0.0.1:6379> select tokens
(error) ERR invalid DB index

It looks like the value should be between 0 and 15.

The documentation is not really clear about this: https://redis.io/commands/select. So I am not 100% sure.

@jhonnynho
Copy link

@B-Galati, well, in my case I use a LIST on redis. For me works ok, I don't get errors adding a string like a list name.

On Redis CLI I put "KEYS *" and I can see my list.

@B-Galati
Copy link
Collaborator Author

@jhonnynho Sorry, I meant that REDIS_DBIDX value is used by the SELECT command under the wood in order to select the database index that the connection should use.

I am not sure what you meant with LIST command.
I do think that before that PR, your REDIS_DBIDX value was either : removed, replaced by 0 or replaced by 1.
So it looked like it was working but it was not really working as expected.

Please let me know If I am misunderstanding something.

@jhonnynho
Copy link

@B-Galati, well, let's see, in my case, I use Redis to set in a List all the tokens generated on the system. So I run the "lpush" and "lrange" to work with that list. I understand Redis do a SELECT to select the database. I'm not defining a redis database, maybe Redis create one per default and inside that it creates the list that I use. I supose.

@B-Galati
Copy link
Collaborator Author

Exactly that. The default database index is 0.

@curry684
Copy link
Collaborator

curry684 commented Jun 28, 2018

The documentation is not really clear about this

It is?

Select the Redis logical database having the specified zero-based numeric index. New connections always use the database 0.

It's numeric, so tokens is invalid and must throw.

Also refer to http://www.rediscookbook.org/multiple_databases.html:

In Redis, databases are identified by an integer index, not by a database name. By default, a client is connected to database 0. With the SELECT command you can switch to a different database:

redis> select 3
OK

All subsequent commands will then use database 3, until you issue another SELECT.

@B-Galati
Copy link
Collaborator Author

My bad, thank you @curry684 👍

curry684 pushed a commit that referenced this pull request Jul 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
on-hold Will not be merged or solved until other tasks have been performed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants