@@ -54,8 +54,9 @@ public function createClient($uri)
54
54
$ parts = parse_url ($ uri );
55
55
}
56
56
57
+ $ uri = preg_replace (array ('/(:)[^:\/]*(@)/ ' , '/([?&]password=).*?($|&)/ ' ), '$1***$2 ' , $ uri );
57
58
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 ' ));
59
60
}
60
61
61
62
$ args = array ();
@@ -70,9 +71,9 @@ public function createClient($uri)
70
71
}
71
72
$ connecting = $ this ->connector ->connect ($ authority );
72
73
73
- $ deferred = new Deferred (function ($ _ , $ reject ) use ($ connecting ) {
74
+ $ deferred = new Deferred (function ($ _ , $ reject ) use ($ connecting, $ uri ) {
74
75
// 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 ' ));
76
77
77
78
// either close successful connection or cancel pending connection attempt
78
79
$ connecting ->then (function (ConnectionInterface $ connection ) {
@@ -84,9 +85,9 @@ public function createClient($uri)
84
85
$ protocol = $ this ->protocol ;
85
86
$ promise = $ connecting ->then (function (ConnectionInterface $ stream ) use ($ protocol ) {
86
87
return new StreamingClient ($ stream , $ protocol ->createResponseParser (), $ protocol ->createSerializer ());
87
- }, function (\Exception $ e ) {
88
+ }, function (\Exception $ e ) use ( $ uri ) {
88
89
throw new \RuntimeException (
89
- 'Connection to Redis server failed because underlying transport connection failed ' ,
90
+ 'Connection to ' . $ uri . ' failed: ' . $ e -> getMessage () ,
90
91
0 ,
91
92
$ e
92
93
);
@@ -96,18 +97,18 @@ public function createClient($uri)
96
97
$ pass = isset ($ args ['password ' ]) ? $ args ['password ' ] : (isset ($ parts ['pass ' ]) ? rawurldecode ($ parts ['pass ' ]) : null );
97
98
if (isset ($ args ['password ' ]) || isset ($ parts ['pass ' ])) {
98
99
$ 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 ) {
100
101
return $ client ->auth ($ pass )->then (
101
102
function () use ($ client ) {
102
103
return $ client ;
103
104
},
104
- function ($ error ) use ($ client ) {
105
+ function (\ Exception $ e ) use ($ client, $ uri ) {
105
106
$ client ->close ();
106
107
107
108
throw new \RuntimeException (
108
- 'Connection to Redis server failed because AUTH command failed ' ,
109
+ 'Connection to ' . $ uri . ' failed during AUTH command: ' . $ e -> getMessage () ,
109
110
0 ,
110
- $ error
111
+ $ e
111
112
);
112
113
}
113
114
);
@@ -117,18 +118,18 @@ function ($error) use ($client) {
117
118
// use `?db=1` query or `/1` path (skip first slash)
118
119
if (isset ($ args ['db ' ]) || (isset ($ parts ['path ' ]) && $ parts ['path ' ] !== '/ ' )) {
119
120
$ 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 ) {
121
122
return $ client ->select ($ db )->then (
122
123
function () use ($ client ) {
123
124
return $ client ;
124
125
},
125
- function ($ error ) use ($ client ) {
126
+ function (\ Exception $ e ) use ($ client, $ uri ) {
126
127
$ client ->close ();
127
128
128
129
throw new \RuntimeException (
129
- 'Connection to Redis server failed because SELECT command failed ' ,
130
+ 'Connection to ' . $ uri . ' failed during SELECT command: ' . $ e -> getMessage () ,
130
131
0 ,
131
- $ error
132
+ $ e
132
133
);
133
134
}
134
135
);
@@ -143,10 +144,10 @@ function ($error) use ($client) {
143
144
return $ deferred ->promise ();
144
145
}
145
146
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 ) {
147
148
if ($ e instanceof TimeoutException) {
148
149
throw new \RuntimeException (
149
- 'Connection to Redis server timed out after ' . $ e ->getTimeout () . ' seconds '
150
+ 'Connection to ' . $ uri . ' timed out after ' . $ e ->getTimeout () . ' seconds '
150
151
);
151
152
}
152
153
throw $ e ;
0 commit comments