Skip to content

Commit 7318393

Browse files
wachterjohannesalexander-schranz
authored andcommitted
Allow auth in redis-transport (#16)
* allow auth in redis-transport * Allow only messenger 4.2.* to avoid conflicts * Fix auth variable in RedisStreamTransport construct
1 parent c5096a3 commit 7318393

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

Transport/RedisStreamTransport.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,20 @@ class RedisStreamTransport implements TransportInterface
6565
* @var SerializerInterface
6666
*/
6767
private $serializer;
68+
/**
69+
* @var string|null
70+
*/
71+
private $auth;
6872

69-
public function __construct(string $host, int $port, string $stream, string $group = '', string $consumer = '', ?SerializerInterface $serializer = null)
73+
public function __construct(string $host, int $port, string $stream, string $group = '', string $consumer = '', ?SerializerInterface $serializer = null, ?string $auth = null)
7074
{
7175
$this->host = $host;
7276
$this->port = $port;
7377
$this->stream = $stream;
7478
$this->group = $group;
7579
$this->consumer = $consumer;
7680
$this->serializer = $serializer ?? Serializer::create();
81+
$this->auth = $auth;
7782
}
7883

7984
public function receive(callable $handler): void
@@ -111,6 +116,9 @@ private function getRedis(): Redis
111116
{
112117
$this->redis = new Redis();
113118
$this->redis->connect($this->host, $this->port);
119+
if ($this->auth) {
120+
$this->redis->auth($this->auth);
121+
}
114122

115123
return $this->redis;
116124
}

Transport/RedisStreamTransportFactory.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ public function createTransport(string $dsn, array $options): TransportInterface
3333
$stream = $dsnParts[1];
3434
$group = $dsnParts[2] ?? '';
3535
$consumer = $dsnParts[3] ?? '';
36+
$auth = $parsedUrl['user'] ?? null;
3637

37-
return new RedisStreamTransport($parsedUrl['host'], $parsedUrl['port'], $stream, $group, $consumer);
38+
return new RedisStreamTransport($parsedUrl['host'], $parsedUrl['port'], $stream, $group, $consumer, null, $auth);
3839
}
3940

4041
public function supports(string $dsn, array $options): bool

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"license": "MIT",
66
"require": {
77
"php": "^7.1",
8-
"ext-redis": "^4.2",
9-
"symfony/messenger": "^4.2",
8+
"ext-redis": "^4.2 || ^5.0",
9+
"symfony/messenger": "4.2.*",
1010
"symfony/config": "^3.4 || ^4.0",
1111
"symfony/dependency-injection": "^3.4 || ^4.0",
1212
"symfony/serializer": "^3.4 || ^4.0",

0 commit comments

Comments
 (0)