@@ -52,7 +52,7 @@ public function createClient($target)
52
52
53
53
$ protocol = $ this ->protocol ;
54
54
55
- $ promise = $ this ->connector ->connect ($ parts ['host ' ] . ' : ' . $ parts [ ' port ' ])->then (function (ConnectionInterface $ stream ) use ($ protocol ) {
55
+ $ promise = $ this ->connector ->connect ($ parts ['authority ' ])->then (function (ConnectionInterface $ stream ) use ($ protocol ) {
56
56
return new StreamingClient ($ stream , $ protocol ->createResponseParser (), $ protocol ->createSerializer ());
57
57
});
58
58
@@ -89,11 +89,18 @@ function ($error) use ($client) {
89
89
90
90
/**
91
91
* @param string $target
92
- * @return array with keys host, port , auth and db
92
+ * @return array with keys authority , auth and db
93
93
* @throws InvalidArgumentException
94
94
*/
95
95
private function parseUrl ($ target )
96
96
{
97
+ $ ret = array ();
98
+ // support `redis+unix://` scheme for Unix domain socket (UDS) paths
99
+ if (preg_match ('/^redis\+unix:\/\/([^:]*:[^@]*@)?(.+?)(\?.*)?$/ ' , $ target , $ match )) {
100
+ $ ret ['authority ' ] = 'unix:// ' . $ match [2 ];
101
+ $ target = 'redis:// ' . (isset ($ match [1 ]) ? $ match [1 ] : '' ) . 'localhost ' . (isset ($ match [3 ]) ? $ match [3 ] : '' );
102
+ }
103
+
97
104
if (strpos ($ target , ':// ' ) === false ) {
98
105
$ target = 'redis:// ' . $ target ;
99
106
}
@@ -103,38 +110,35 @@ private function parseUrl($target)
103
110
throw new InvalidArgumentException ('Given URL can not be parsed ' );
104
111
}
105
112
106
- if (!isset ($ parts ['port ' ])) {
107
- $ parts ['port ' ] = 6379 ;
108
- }
109
-
110
113
if (isset ($ parts ['pass ' ])) {
111
- $ parts ['auth ' ] = rawurldecode ($ parts ['pass ' ]);
114
+ $ ret ['auth ' ] = rawurldecode ($ parts ['pass ' ]);
112
115
}
113
116
114
117
if (isset ($ parts ['path ' ]) && $ parts ['path ' ] !== '' ) {
115
118
// skip first slash
116
- $ parts ['db ' ] = substr ($ parts ['path ' ], 1 );
119
+ $ ret ['db ' ] = substr ($ parts ['path ' ], 1 );
117
120
}
118
121
119
- if ($ parts ['scheme ' ] === 'rediss ' ) {
120
- $ parts ['host ' ] = 'tls:// ' . $ parts ['host ' ];
122
+ if (!isset ($ ret ['authority ' ])) {
123
+ $ ret ['authority ' ] =
124
+ ($ parts ['scheme ' ] === 'rediss ' ? 'tls:// ' : '' ) .
125
+ $ parts ['host ' ] . ': ' .
126
+ (isset ($ parts ['port ' ]) ? $ parts ['port ' ] : 6379 );
121
127
}
122
128
123
129
if (isset ($ parts ['query ' ])) {
124
130
$ args = array ();
125
131
parse_str ($ parts ['query ' ], $ args );
126
132
127
133
if (isset ($ args ['password ' ])) {
128
- $ parts ['auth ' ] = $ args ['password ' ];
134
+ $ ret ['auth ' ] = $ args ['password ' ];
129
135
}
130
136
131
137
if (isset ($ args ['db ' ])) {
132
- $ parts ['db ' ] = $ args ['db ' ];
138
+ $ ret ['db ' ] = $ args ['db ' ];
133
139
}
134
140
}
135
141
136
- unset($ parts ['scheme ' ], $ parts ['user ' ], $ parts ['pass ' ], $ parts ['path ' ]);
137
-
138
- return $ parts ;
142
+ return $ ret ;
139
143
}
140
144
}
0 commit comments