Skip to content

Commit c88de24

Browse files
committed
Parse url key in Redis configuration.
1 parent 39c115d commit c88de24

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

src/Illuminate/Redis/RedisManager.php

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use InvalidArgumentException;
66
use Illuminate\Contracts\Redis\Factory;
77
use Illuminate\Redis\Connections\Connection;
8+
use Illuminate\Support\ConfigurationUrlParser;
89

910
/**
1011
* @mixin \Illuminate\Redis\Connections\Connection
@@ -95,7 +96,9 @@ public function resolve($name = null)
9596
$options = $this->config['options'] ?? [];
9697

9798
if (isset($this->config[$name])) {
98-
return $this->connector()->connect($this->config[$name], $options);
99+
return $this->connector()->connect(
100+
$this->parseConnectionConfigWithUrl($this->config[$name]), $options
101+
);
99102
}
100103

101104
if (isset($this->config['clusters'][$name])) {
@@ -113,10 +116,10 @@ public function resolve($name = null)
113116
*/
114117
protected function resolveCluster($name)
115118
{
116-
$clusterOptions = $this->config['clusters']['options'] ?? [];
117-
118119
return $this->connector()->connectToCluster(
119-
$this->config['clusters'][$name], $clusterOptions, $this->config['options'] ?? []
120+
$this->parseConnectionConfigWithUrl($this->config['clusters'][$name]),
121+
$this->config['clusters']['options'] ?? [],
122+
$this->config['options'] ?? []
120123
);
121124
}
122125

@@ -153,6 +156,21 @@ protected function connector()
153156
}
154157
}
155158

159+
/**
160+
* Parse the redis configuration, hydrating options using a redis configuration URL if possible.
161+
*
162+
* @param array $config
163+
* @return array
164+
*/
165+
protected function parseConnectionConfigWithUrl($config)
166+
{
167+
$parsedConfig = (new ConfigurationUrlParser)->parseConfiguration($config);
168+
169+
return array_filter($parsedConfig, function ($key) {
170+
return !in_array($key, ['driver', 'username']);
171+
}, ARRAY_FILTER_USE_KEY);
172+
}
173+
156174
/**
157175
* Return all of the created connections.
158176
*

0 commit comments

Comments
 (0)