@@ -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