@@ -73,22 +73,15 @@ public function __construct(array $configuration, array $connectionCredentials =
73
73
74
74
public static function fromDsn (string $ dsn , array $ redisOptions = [], \Redis $ redis = null ): self
75
75
{
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 ;
85
77
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
+ }
91
81
82
+ if (false === $ parsedUrl = parse_url ($ url )) {
83
+ throw new InvalidArgumentException (sprintf ('The given Redis DSN "%s" is invalid. ' , $ dsn ));
84
+ }
92
85
if (isset ($ parsedUrl ['query ' ])) {
93
86
parse_str ($ parsedUrl ['query ' ], $ redisOptions );
94
87
}
@@ -111,14 +104,35 @@ public static function fromDsn(string $dsn, array $redisOptions = [], \Redis $re
111
104
unset($ redisOptions ['dbindex ' ]);
112
105
}
113
106
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 ,
118
111
'auto_setup ' => $ autoSetup ,
119
112
'stream_max_entries ' => $ maxEntries ,
120
113
'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 );
122
136
}
123
137
124
138
public function get (): ?array
0 commit comments