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

IPv6 support #147

Merged
merged 1 commit into from
Apr 6, 2018
Merged

IPv6 support #147

merged 1 commit into from
Apr 6, 2018

Conversation

snc
Copy link
Owner

@snc snc commented Aug 10, 2014

Can you add this feature to bundle?
I made this changes to RedisDsn class in method parseDsn:

    if (preg_match('#^([^:]+)(:(\d+))?$#', $dsn, $matches)) {   //IPv4
        if (!empty($matches[1])) {
            // parse host/ip or socket
            if ('/' === $matches[1]{0}) {
                $this->socket = $matches[1];
            } else {
                $this->host = $matches[1];
            }
        }
        if (null === $this->socket && !empty($matches[3])) {
            // parse port
            $this->port = (int) $matches[3];
        }
    } elseif (preg_match('#^([^.]+)(.(\d+))?$#', $dsn, $matches)) { //IPv6
        if (!empty($matches[1])) {
            // parse host/ip or socket
            if ('/' === $matches[1]{0}) {
                $this->socket = $matches[1];
            } else {
                $this->host = $matches[1];
            }
        }
        if (null === $this->socket && !empty($matches[3])) {
            // parse port
            $this->port = (int) $matches[3];
        }
    }

If this is correct, add it to your repository plz

@snc snc added the DX label Aug 7, 2014
@snc
Copy link
Owner

snc commented Aug 9, 2014

The problem here are the different valid IPv6 formats when used together with a port number.

Some examples of valid IPv6 addresses:
::1
1050:0000:0000:0000:0005:0600:300c:326b
1050:0:0:0:5:600:300c:326b
ff06:0:0:0:0:0:0:c3
ff06::c3

A good regex for this is
'#^(((?=(?>.*?(::))(?!.+\3)))\3?|([\dA-F]{1,4}(\3|:(?!$)|$)|\2))(?4){5}((?4){2}|(25[0-5]|(2[0-4]|1\d|[1-9])?\d)(\.(?7)){3})\z#i'

Resulting DSNs:
redis://ff06::c3
redis://ff06::c3/1

Now when a port is given we have a problem:
redis://ff06::c3:6379

It's impossible to say if :6379 belongs to the IP or not.

@nrk
Copy link
Contributor

nrk commented Aug 9, 2014

IPv6 addresses expressed in URL's syntax should be enclosed in square brackets, for example: redis://[ff06::c3]:6379/1

@snc
Copy link
Owner

snc commented Aug 10, 2014

Nice suggestion @nrk 👍
I just converted this issue to a PR. Can you test it @Quidle?

Copy link
Collaborator

@Seldaek Seldaek left a comment

Choose a reason for hiding this comment

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

Looks good to me, and harmless enough to merge?

@Seldaek Seldaek added this to the 2.0 milestone Mar 29, 2018
@Seldaek Seldaek merged commit a2c17e3 into 1.1 Apr 6, 2018
@Seldaek Seldaek deleted the issue-147 branch April 6, 2018 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dx Developer eXperience
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants