[Messenger] Messenger redis local sock dsn
This commit is contained in:
parent
b350c80fc3
commit
0421e01ae1
@ -54,6 +54,17 @@ class ConnectionTest extends TestCase
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testFromDsnOnUnixSocket()
|
||||||
|
{
|
||||||
|
$this->assertEquals(
|
||||||
|
new Connection(['stream' => 'queue'], [
|
||||||
|
'host' => '/var/run/redis/redis.sock',
|
||||||
|
'port' => 0,
|
||||||
|
], [], $redis = $this->createMock(\Redis::class)),
|
||||||
|
Connection::fromDsn('redis:///var/run/redis/redis.sock', ['stream' => 'queue'], $redis)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public function testFromDsnWithOptions()
|
public function testFromDsnWithOptions()
|
||||||
{
|
{
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
|
@ -73,22 +73,15 @@ class Connection
|
|||||||
|
|
||||||
public static function fromDsn(string $dsn, array $redisOptions = [], \Redis $redis = null): self
|
public static function fromDsn(string $dsn, array $redisOptions = [], \Redis $redis = null): self
|
||||||
{
|
{
|
||||||
if (false === $parsedUrl = parse_url($dsn)) {
|
$url = $dsn;
|
||||||
throw new InvalidArgumentException(sprintf('The given Redis DSN "%s" is invalid.', $dsn));
|
|
||||||
|
if (preg_match('#^redis:///([^:@])+$#', $dsn)) {
|
||||||
|
$url = str_replace('redis:', 'file:', $dsn);
|
||||||
}
|
}
|
||||||
|
|
||||||
$pathParts = explode('/', $parsedUrl['path'] ?? '');
|
if (false === $parsedUrl = parse_url($url)) {
|
||||||
|
throw new InvalidArgumentException(sprintf('The given Redis DSN "%s" is invalid.', $dsn));
|
||||||
$stream = $pathParts[1] ?? $redisOptions['stream'] ?? null;
|
}
|
||||||
$group = $pathParts[2] ?? $redisOptions['group'] ?? null;
|
|
||||||
$consumer = $pathParts[3] ?? $redisOptions['consumer'] ?? null;
|
|
||||||
|
|
||||||
$connectionCredentials = [
|
|
||||||
'host' => $parsedUrl['host'] ?? '127.0.0.1',
|
|
||||||
'port' => $parsedUrl['port'] ?? 6379,
|
|
||||||
'auth' => $parsedUrl['pass'] ?? $parsedUrl['user'] ?? null,
|
|
||||||
];
|
|
||||||
|
|
||||||
if (isset($parsedUrl['query'])) {
|
if (isset($parsedUrl['query'])) {
|
||||||
parse_str($parsedUrl['query'], $redisOptions);
|
parse_str($parsedUrl['query'], $redisOptions);
|
||||||
}
|
}
|
||||||
@ -111,14 +104,35 @@ class Connection
|
|||||||
unset($redisOptions['dbindex']);
|
unset($redisOptions['dbindex']);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new self([
|
$configuration = [
|
||||||
'stream' => $stream,
|
'stream' => $redisOptions['stream'] ?? null,
|
||||||
'group' => $group,
|
'group' => $redisOptions['group'] ?? null,
|
||||||
'consumer' => $consumer,
|
'consumer' => $redisOptions['consumer'] ?? null,
|
||||||
'auto_setup' => $autoSetup,
|
'auto_setup' => $autoSetup,
|
||||||
'stream_max_entries' => $maxEntries,
|
'stream_max_entries' => $maxEntries,
|
||||||
'dbindex' => $dbIndex,
|
'dbindex' => $dbIndex,
|
||||||
], $connectionCredentials, $redisOptions, $redis);
|
];
|
||||||
|
|
||||||
|
if (isset($parsedUrl['host'])) {
|
||||||
|
$connectionCredentials = [
|
||||||
|
'host' => $parsedUrl['host'] ?? '127.0.0.1',
|
||||||
|
'port' => $parsedUrl['port'] ?? 6379,
|
||||||
|
'auth' => $parsedUrl['pass'] ?? $parsedUrl['user'] ?? null,
|
||||||
|
];
|
||||||
|
|
||||||
|
$pathParts = explode('/', $parsedUrl['path'] ?? '');
|
||||||
|
|
||||||
|
$configuration['stream'] = $pathParts[1] ?? $configuration['stream'];
|
||||||
|
$configuration['group'] = $pathParts[2] ?? $configuration['group'];
|
||||||
|
$configuration['consumer'] = $pathParts[3] ?? $configuration['consumer'];
|
||||||
|
} else {
|
||||||
|
$connectionCredentials = [
|
||||||
|
'host' => $parsedUrl['path'],
|
||||||
|
'port' => 0,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return new self($configuration, $connectionCredentials, $redisOptions, $redis);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get(): ?array
|
public function get(): ?array
|
||||||
|
Reference in New Issue
Block a user