@@ -12,13 +12,15 @@ import std.typetuple;
1212import std.exception ;
1313
1414public import redis;
15+ import std.socket ;
1516public class Redis
1617{
1718 import std.socket : TcpSocket , InternetAddress ;
1819
1920 private :
2021 TcpSocket [string ] conns;
2122 string addr;
23+ string password;
2224 public :
2325
2426 mixin keyCommands;
@@ -39,6 +41,7 @@ public class Redis
3941 conns[addr] = conn;
4042 writeln(password);
4143 writeln(" AUTH " ~ password);
44+ this .password = password;
4245 if (password.length > 0 ){
4346 conn.send(toMultiBulk(" AUTH" , password));
4447 Response[] r = receiveResponses(conn, 1 );
@@ -117,16 +120,16 @@ public class Redis
117120 */
118121 R sendRaw (R = Response)(string cmd)
119122 {
120- SENDRAW :
121- auto conn = conns[addr];
123+ SEND :
124+
122125 debug (redis) { writeln(escape(cmd));}
123126
124127 conn.send(cmd);
125128 Response[] r = receiveResponses(conn, 1 );
126129 if (r.length && r[0 ].isMoved)
127130 {
128131 addr = ((split(r[0 ].toString," " ))[2 ]);
129- goto SENDRAW ;
132+ goto SEND ;
130133 }
131134 return cast (R)(r[0 ]);
132135 }
@@ -219,6 +222,25 @@ public class Redis
219222 if (addr ! in conns){
220223 auto arr = split(addr," :" );
221224 conns[addr] = new TcpSocket (new InternetAddress (arr[0 ], arr[1 ].to! ushort ));
225+ if (password.length > 0 ){
226+ conns[addr].send(toMultiBulk(" AUTH" , password));
227+ Response[] r = receiveResponses(conns[addr], 1 );
228+ }
229+ }
230+
231+ int error;
232+ conns[addr].getOption(SocketOptionLevel.SOCKET , SocketOption.ERROR , error);
233+ if (error != 0 )
234+ {
235+ conns[addr].close();
236+ auto arr = split(addr," :" );
237+ conns[addr] = new TcpSocket (new InternetAddress (arr[0 ], arr[1 ].to! ushort ));
238+ if (password.length > 0 ){
239+ conns[addr].send(toMultiBulk(" AUTH" , password));
240+ Response[] r = receiveResponses(conns[addr], 1 );
241+ }
242+ throw new ConnectionException(" Error while sending request, error " ~ to! string (error));
243+
222244 }
223245 return conns[addr];
224246 }
0 commit comments