@@ -54,8 +54,9 @@ public function createClient($uri)
5454 $ parts = parse_url ($ uri );
5555 }
5656
57+ $ uri = preg_replace (array ('/(:)[^:\/]*(@)/ ' , '/([?&]password=).*?($|&)/ ' ), '$1***$2 ' , $ uri );
5758 if ($ parts === false || !isset ($ parts ['scheme ' ], $ parts ['host ' ]) || !in_array ($ parts ['scheme ' ], array ('redis ' , 'rediss ' , 'redis+unix ' ))) {
58- return \React \Promise \reject (new \InvalidArgumentException ('Given URL can not be parsed ' ));
59+ return \React \Promise \reject (new \InvalidArgumentException ('Invalid Redis URI given ' ));
5960 }
6061
6162 $ args = array ();
@@ -70,9 +71,9 @@ public function createClient($uri)
7071 }
7172 $ connecting = $ this ->connector ->connect ($ authority );
7273
73- $ deferred = new Deferred (function ($ _ , $ reject ) use ($ connecting ) {
74+ $ deferred = new Deferred (function ($ _ , $ reject ) use ($ connecting, $ uri ) {
7475 // connection cancelled, start with rejecting attempt, then clean up
75- $ reject (new \RuntimeException ('Connection to Redis server cancelled ' ));
76+ $ reject (new \RuntimeException ('Connection to ' . $ uri . ' cancelled ' ));
7677
7778 // either close successful connection or cancel pending connection attempt
7879 $ connecting ->then (function (ConnectionInterface $ connection ) {
@@ -84,9 +85,9 @@ public function createClient($uri)
8485 $ protocol = $ this ->protocol ;
8586 $ promise = $ connecting ->then (function (ConnectionInterface $ stream ) use ($ protocol ) {
8687 return new StreamingClient ($ stream , $ protocol ->createResponseParser (), $ protocol ->createSerializer ());
87- }, function (\Exception $ e ) {
88+ }, function (\Exception $ e ) use ( $ uri ) {
8889 throw new \RuntimeException (
89- 'Connection to Redis server failed because underlying transport connection failed ' ,
90+ 'Connection to ' . $ uri . ' failed: ' . $ e -> getMessage () ,
9091 0 ,
9192 $ e
9293 );
@@ -96,18 +97,18 @@ public function createClient($uri)
9697 $ pass = isset ($ args ['password ' ]) ? $ args ['password ' ] : (isset ($ parts ['pass ' ]) ? rawurldecode ($ parts ['pass ' ]) : null );
9798 if (isset ($ args ['password ' ]) || isset ($ parts ['pass ' ])) {
9899 $ pass = isset ($ args ['password ' ]) ? $ args ['password ' ] : rawurldecode ($ parts ['pass ' ]);
99- $ promise = $ promise ->then (function (StreamingClient $ client ) use ($ pass ) {
100+ $ promise = $ promise ->then (function (StreamingClient $ client ) use ($ pass, $ uri ) {
100101 return $ client ->auth ($ pass )->then (
101102 function () use ($ client ) {
102103 return $ client ;
103104 },
104- function ($ error ) use ($ client ) {
105+ function (\ Exception $ e ) use ($ client, $ uri ) {
105106 $ client ->close ();
106107
107108 throw new \RuntimeException (
108- 'Connection to Redis server failed because AUTH command failed ' ,
109+ 'Connection to ' . $ uri . ' failed during AUTH command: ' . $ e -> getMessage () ,
109110 0 ,
110- $ error
111+ $ e
111112 );
112113 }
113114 );
@@ -117,18 +118,18 @@ function ($error) use ($client) {
117118 // use `?db=1` query or `/1` path (skip first slash)
118119 if (isset ($ args ['db ' ]) || (isset ($ parts ['path ' ]) && $ parts ['path ' ] !== '/ ' )) {
119120 $ db = isset ($ args ['db ' ]) ? $ args ['db ' ] : substr ($ parts ['path ' ], 1 );
120- $ promise = $ promise ->then (function (StreamingClient $ client ) use ($ db ) {
121+ $ promise = $ promise ->then (function (StreamingClient $ client ) use ($ db, $ uri ) {
121122 return $ client ->select ($ db )->then (
122123 function () use ($ client ) {
123124 return $ client ;
124125 },
125- function ($ error ) use ($ client ) {
126+ function (\ Exception $ e ) use ($ client, $ uri ) {
126127 $ client ->close ();
127128
128129 throw new \RuntimeException (
129- 'Connection to Redis server failed because SELECT command failed ' ,
130+ 'Connection to ' . $ uri . ' failed during SELECT command: ' . $ e -> getMessage () ,
130131 0 ,
131- $ error
132+ $ e
132133 );
133134 }
134135 );
@@ -143,10 +144,10 @@ function ($error) use ($client) {
143144 return $ deferred ->promise ();
144145 }
145146
146- return \React \Promise \Timer \timeout ($ deferred ->promise (), $ timeout , $ this ->loop )->then (null , function ($ e ) {
147+ return \React \Promise \Timer \timeout ($ deferred ->promise (), $ timeout , $ this ->loop )->then (null , function ($ e ) use ( $ uri ) {
147148 if ($ e instanceof TimeoutException) {
148149 throw new \RuntimeException (
149- 'Connection to Redis server timed out after ' . $ e ->getTimeout () . ' seconds '
150+ 'Connection to ' . $ uri . ' timed out after ' . $ e ->getTimeout () . ' seconds '
150151 );
151152 }
152153 throw $ e ;
0 commit comments