Skip to content

Commit

Permalink
Added IPv6 support
Browse files Browse the repository at this point in the history
  • Loading branch information
snc authored and Seldaek committed Apr 6, 2018
1 parent 8e8ec51 commit e43b593
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
7 changes: 7 additions & 0 deletions DependencyInjection/Configuration/RedisDsn.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,13 @@ protected function parseDsn($dsn)
// parse port
$this->port = is_numeric($matches[3]) ? (int) $matches[3] : $matches[3];
}
} elseif (preg_match('#^\[([^\]]+)](:(\d+))?$#', $dsn, $matches)) { // parse enclosed IPv6 address and optional port
if (!empty($matches[1])) {
$this->host = $matches[1];
}
if (!empty($matches[3])) {
$this->port = (int) $matches[3];
}
}
}

Expand Down
25 changes: 25 additions & 0 deletions Tests/DependencyInjection/Configuration/RedisDsnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,31 @@ public static function hostValues()
array('redis://127.0.0.1:63790', '127.0.0.1'),
array('redis://127.0.0.1:63790/10', '127.0.0.1'),
array('redis://[email protected]:63790/10', '127.0.0.1'),
array('redis://[::1]', '::1'),
array('redis://[::1]/1', '::1'),
array('redis://[::1]:63790', '::1'),
array('redis://[::1]:63790/10', '::1'),
array('redis://pw@[::1]:63790/10', '::1'),
array('redis://[1050:0000:0000:0000:0005:0600:300c:326b]', '1050:0000:0000:0000:0005:0600:300c:326b'),
array('redis://[1050:0000:0000:0000:0005:0600:300c:326b]/1', '1050:0000:0000:0000:0005:0600:300c:326b'),
array('redis://[1050:0000:0000:0000:0005:0600:300c:326b]:63790', '1050:0000:0000:0000:0005:0600:300c:326b'),
array('redis://[1050:0000:0000:0000:0005:0600:300c:326b]:63790/10', '1050:0000:0000:0000:0005:0600:300c:326b'),
array('redis://pw@[1050:0000:0000:0000:0005:0600:300c:326b]:63790/10', '1050:0000:0000:0000:0005:0600:300c:326b'),
array('redis://[1050:0:0:0:5:600:300c:326b]', '1050:0:0:0:5:600:300c:326b'),
array('redis://[1050:0:0:0:5:600:300c:326b]/1', '1050:0:0:0:5:600:300c:326b'),
array('redis://[1050:0:0:0:5:600:300c:326b]:63790', '1050:0:0:0:5:600:300c:326b'),
array('redis://[1050:0:0:0:5:600:300c:326b]:63790/10', '1050:0:0:0:5:600:300c:326b'),
array('redis://pw@[1050:0:0:0:5:600:300c:326b]:63790/10', '1050:0:0:0:5:600:300c:326b'),
array('redis://[ff06:0:0:0:0:0:0:c3]', 'ff06:0:0:0:0:0:0:c3'),
array('redis://[ff06:0:0:0:0:0:0:c3]/1', 'ff06:0:0:0:0:0:0:c3'),
array('redis://[ff06:0:0:0:0:0:0:c3]:63790', 'ff06:0:0:0:0:0:0:c3'),
array('redis://[ff06:0:0:0:0:0:0:c3]:63790/10', 'ff06:0:0:0:0:0:0:c3'),
array('redis://pw@[ff06:0:0:0:0:0:0:c3]:63790/10', 'ff06:0:0:0:0:0:0:c3'),
array('redis://[ff06::c3]', 'ff06::c3'),
array('redis://[ff06::c3]/1', 'ff06::c3'),
array('redis://[ff06::c3]:63790', 'ff06::c3'),
array('redis://[ff06::c3]:63790/10', 'ff06::c3'),
array('redis://pw@[ff06::c3]:63790/10', 'ff06::c3'),
array('redis://%redis_host%', '%redis_host%'),
array('redis://%redis_host%/%redis_db%', '%redis_host%'),
array('redis://%redis_host%:%redis_port%', '%redis_host%'),
Expand Down

0 comments on commit e43b593

Please sign in to comment.