Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Cache] Fix connecting to Redis via a socket file #45281

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

Merged
merged 1 commit into from
Feb 4, 2022
Merged

[Cache] Fix connecting to Redis via a socket file #45281

merged 1 commit into from
Feb 4, 2022

Conversation

alebedev80
Copy link
Contributor

@alebedev80 alebedev80 commented Feb 2, 2022

Q A
Branch? 4.4
Bug fix? yes
New feature? no
Deprecations? no
Tickets #45277
License MIT
Doc PR

In the commit was done follow changes in Traits/RedisTrait.php(188)

Old code:

$port = $hosts[0]['port'] ?? null;

New code:

$port = $hosts[0]['port'] ?? 6379;

With DSN "redis:///var/run/redis/redis.sock" raise an error:

Redis connection "redis:///var/run/redis/redis.sock?dbindex=5" failed: php_network_getaddresses: getaddrinfo failed: Name or service not known

Because phpredis doesn't allow socket connections with a port

(new Redis)->connect('/var/run/redis/redis.sock', 6379);

Error

PHP Warning:  Redis::connect(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /root/test_redis.php on line 5
PHP Fatal error:  Uncaught RedisException: php_network_getaddresses: getaddrinfo failed: Name or service not known in /root/test_redis.php:5
Stack trace:
#0 /root/test_redis.php(5): Redis->connect()
#1 {main}
  thrown in /root/test_redis.php on line 5

I added additional validation of connection type (by host or socket). Also I fixed condition when RedisSentinel connection call as it supports connections by host only.

@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has a contribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (see https://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (see https://symfony.com/releases)
  • Features and deprecations must be submitted against the 6.1 branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@alebedev80 alebedev80 changed the title [RedisComponent ]Bug fix a socket connection without port in RedisTrait.php [RedisComponent] Bug fix a socket connection without port in RedisTrait.php Feb 2, 2022
@alebedev80 alebedev80 changed the title [RedisComponent] Bug fix a socket connection without port in RedisTrait.php [CacheComponent] Bug fix a socket connection without port in RedisTrait.php Feb 2, 2022
@alebedev80
Copy link
Contributor Author

alebedev80 commented Feb 2, 2022

@kbond I did a first PR to Symfony project and had some issues:

  1. why change from that files also was committed src/Symfony/Component/Mailer/Bridge/Mailchimp/*
  2. tests failed, but on local envirionment they skipped. How to set-up local env so test runs ok?
Symfony\Component\Cache\Exception\InvalidArgumentException: Invalid Redis DSN: "redis://".```

Please help me!

@kbond
Copy link
Member

kbond commented Feb 2, 2022

Hey @alebedev80, thanks for contributing!

For (1), a few things:

  1. Not exactly sure why these extra commits are included, did you perhaps merge 6.1 into your PR?
  2. Regardless, 5.4 is where you want to make this change so fetch the latest 5.4 branch from this repo and rebase your branch to it (including only your commits).
  3. You'll then need to change the target of this PR to 5.4 (edit button near the PR title gives this option).

For (2), I think you'll need to run the test suite with the REDIS_HOST env variable set:

REDIS_HOST=... phpunit --group integration

I'm not positive though, let me know if that doesn't work.

@alebedev80 alebedev80 changed the base branch from 6.1 to 5.4 February 2, 2022 15:44
@alebedev80
Copy link
Contributor Author

@kbond test failed with an error:

1) Symfony\Component\Cache\Tests\Adapter\RedisAdapterTest::testCreateSocketConnection
Symfony\Component\Cache\Exception\InvalidArgumentException: Redis connection "redis:///var/run/redis/redis.sock" failed: No such file or directory

as i understand test envirionment start a Redis instance

  1. where i can find Redis configuration?
  2. what's a Redis's socket file path?

Thank you!

@kbond
Copy link
Member

kbond commented Feb 3, 2022

I'll have to ping @nicolas-grekas to help with this.

@alebedev80
Copy link
Contributor Author

@nicolas-grekas please help

@nicolas-grekas nicolas-grekas changed the title [CacheComponent] Bug fix a socket connection without port in RedisTrait.php [Cache] Fix connecting to Redis via a socket file Feb 4, 2022
@nicolas-grekas nicolas-grekas changed the base branch from 5.4 to 4.4 February 4, 2022 16:42
@nicolas-grekas nicolas-grekas modified the milestones: 6.1, 4.4 Feb 4, 2022
@alebedev80 alebedev80 requested a review from jderusse as a code owner February 4, 2022 18:03
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've rebased for 4.4, fixed the patch, and fixed the tests.

@carsonbot carsonbot changed the title [Cache] Fix connecting to Redis via a socket file Fix connecting to Redis via a socket file Feb 4, 2022
@carsonbot carsonbot changed the title Fix connecting to Redis via a socket file [Cache] Fix connecting to Redis via a socket file Feb 4, 2022
@nicolas-grekas
Copy link
Member

Thank you @alebedev80.

@nicolas-grekas nicolas-grekas merged commit 12b63b3 into symfony:4.4 Feb 4, 2022
@alebedev80
Copy link
Contributor Author

@nicolas-grekas thank you very much!

This was referenced Feb 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants