Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0421e01

Browse filesBrowse files
JJarriefabpot
authored andcommitted
[Messenger] Messenger redis local sock dsn
1 parent b350c80 commit 0421e01
Copy full SHA for 0421e01

File tree

2 files changed

+44
-19
lines changed
Filter options

2 files changed

+44
-19
lines changed

‎src/Symfony/Component/Messenger/Tests/Transport/RedisExt/ConnectionTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/Tests/Transport/RedisExt/ConnectionTest.php
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,17 @@ public function testFromDsn()
5454
);
5555
}
5656

57+
public function testFromDsnOnUnixSocket()
58+
{
59+
$this->assertEquals(
60+
new Connection(['stream' => 'queue'], [
61+
'host' => '/var/run/redis/redis.sock',
62+
'port' => 0,
63+
], [], $redis = $this->createMock(\Redis::class)),
64+
Connection::fromDsn('redis:///var/run/redis/redis.sock', ['stream' => 'queue'], $redis)
65+
);
66+
}
67+
5768
public function testFromDsnWithOptions()
5869
{
5970
$this->assertEquals(

‎src/Symfony/Component/Messenger/Transport/RedisExt/Connection.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/Transport/RedisExt/Connection.php
+33-19Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -73,22 +73,15 @@ public function __construct(array $configuration, array $connectionCredentials =
7373

7474
public static function fromDsn(string $dsn, array $redisOptions = [], \Redis $redis = null): self
7575
{
76-
if (false === $parsedUrl = parse_url($dsn)) {
77-
throw new InvalidArgumentException(sprintf('The given Redis DSN "%s" is invalid.', $dsn));
78-
}
79-
80-
$pathParts = explode('/', $parsedUrl['path'] ?? '');
81-
82-
$stream = $pathParts[1] ?? $redisOptions['stream'] ?? null;
83-
$group = $pathParts[2] ?? $redisOptions['group'] ?? null;
84-
$consumer = $pathParts[3] ?? $redisOptions['consumer'] ?? null;
76+
$url = $dsn;
8577

86-
$connectionCredentials = [
87-
'host' => $parsedUrl['host'] ?? '127.0.0.1',
88-
'port' => $parsedUrl['port'] ?? 6379,
89-
'auth' => $parsedUrl['pass'] ?? $parsedUrl['user'] ?? null,
90-
];
78+
if (preg_match('#^redis:///([^:@])+$#', $dsn)) {
79+
$url = str_replace('redis:', 'file:', $dsn);
80+
}
9181

82+
if (false === $parsedUrl = parse_url($url)) {
83+
throw new InvalidArgumentException(sprintf('The given Redis DSN "%s" is invalid.', $dsn));
84+
}
9285
if (isset($parsedUrl['query'])) {
9386
parse_str($parsedUrl['query'], $redisOptions);
9487
}
@@ -111,14 +104,35 @@ public static function fromDsn(string $dsn, array $redisOptions = [], \Redis $re
111104
unset($redisOptions['dbindex']);
112105
}
113106

114-
return new self([
115-
'stream' => $stream,
116-
'group' => $group,
117-
'consumer' => $consumer,
107+
$configuration = [
108+
'stream' => $redisOptions['stream'] ?? null,
109+
'group' => $redisOptions['group'] ?? null,
110+
'consumer' => $redisOptions['consumer'] ?? null,
118111
'auto_setup' => $autoSetup,
119112
'stream_max_entries' => $maxEntries,
120113
'dbindex' => $dbIndex,
121-
], $connectionCredentials, $redisOptions, $redis);
114+
];
115+
116+
if (isset($parsedUrl['host'])) {
117+
$connectionCredentials = [
118+
'host' => $parsedUrl['host'] ?? '127.0.0.1',
119+
'port' => $parsedUrl['port'] ?? 6379,
120+
'auth' => $parsedUrl['pass'] ?? $parsedUrl['user'] ?? null,
121+
];
122+
123+
$pathParts = explode('/', $parsedUrl['path'] ?? '');
124+
125+
$configuration['stream'] = $pathParts[1] ?? $configuration['stream'];
126+
$configuration['group'] = $pathParts[2] ?? $configuration['group'];
127+
$configuration['consumer'] = $pathParts[3] ?? $configuration['consumer'];
128+
} else {
129+
$connectionCredentials = [
130+
'host' => $parsedUrl['path'],
131+
'port' => 0,
132+
];
133+
}
134+
135+
return new self($configuration, $connectionCredentials, $redisOptions, $redis);
122136
}
123137

124138
public function get(): ?array

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.