@@ -52,7 +52,7 @@ public function createClient($target)
5252
5353 $ protocol = $ this ->protocol ;
5454
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 ) {
5656 return new StreamingClient ($ stream , $ protocol ->createResponseParser (), $ protocol ->createSerializer ());
5757 });
5858
@@ -89,11 +89,18 @@ function ($error) use ($client) {
8989
9090 /**
9191 * @param string $target
92- * @return array with keys host, port , auth and db
92+ * @return array with keys authority , auth and db
9393 * @throws InvalidArgumentException
9494 */
9595 private function parseUrl ($ target )
9696 {
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+
97104 if (strpos ($ target , ':// ' ) === false ) {
98105 $ target = 'redis:// ' . $ target ;
99106 }
@@ -103,38 +110,35 @@ private function parseUrl($target)
103110 throw new InvalidArgumentException ('Given URL can not be parsed ' );
104111 }
105112
106- if (!isset ($ parts ['port ' ])) {
107- $ parts ['port ' ] = 6379 ;
108- }
109-
110113 if (isset ($ parts ['pass ' ])) {
111- $ parts ['auth ' ] = rawurldecode ($ parts ['pass ' ]);
114+ $ ret ['auth ' ] = rawurldecode ($ parts ['pass ' ]);
112115 }
113116
114117 if (isset ($ parts ['path ' ]) && $ parts ['path ' ] !== '' ) {
115118 // skip first slash
116- $ parts ['db ' ] = substr ($ parts ['path ' ], 1 );
119+ $ ret ['db ' ] = substr ($ parts ['path ' ], 1 );
117120 }
118121
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 );
121127 }
122128
123129 if (isset ($ parts ['query ' ])) {
124130 $ args = array ();
125131 parse_str ($ parts ['query ' ], $ args );
126132
127133 if (isset ($ args ['password ' ])) {
128- $ parts ['auth ' ] = $ args ['password ' ];
134+ $ ret ['auth ' ] = $ args ['password ' ];
129135 }
130136
131137 if (isset ($ args ['db ' ])) {
132- $ parts ['db ' ] = $ args ['db ' ];
138+ $ ret ['db ' ] = $ args ['db ' ];
133139 }
134140 }
135141
136- unset($ parts ['scheme ' ], $ parts ['user ' ], $ parts ['pass ' ], $ parts ['path ' ]);
137-
138- return $ parts ;
142+ return $ ret ;
139143 }
140144}
0 commit comments