@@ -29,6 +29,8 @@ implements Abstract.RedisClient {
2929
3030 private _password ! : string ;
3131
32+ private _database ! : number ;
33+
3234 private _subscriber ! : SubscriberClient ;
3335
3436 private _listeners ! : Dict < Array < Abstract . SubscriptionCallback | Readable > > ;
@@ -42,6 +44,8 @@ implements Abstract.RedisClient {
4244 ) {
4345
4446 super ( connection , host , port , createDecoder , createEncoder ) ;
47+
48+ this . _database = 0 ;
4549 }
4650
4751 protected async _initializeSubscriber ( ) : Promise < void > {
@@ -145,32 +149,33 @@ implements Abstract.RedisClient {
145149 return this ;
146150 }
147151
148- protected _onReconnected ( ) : void {
152+ protected async _onReconnected ( ) : Promise < void > {
149153
150154 if ( this . _password ) {
151155
152156 /**
153157 * Cache all imcoming commands before authentication completed.
154158 */
155- this . _forcePipeline ( ) . executeNow (
156- "AUTH" , this . _password
157- ) . catch ( ( e ) => {
158-
159- delete this . _password ;
159+ this . _forcePipeline ( ) ;
160160
161- this . emit ( "error" , e ) ;
161+ await this . executeNow (
162+ "AUTH" , this . _password
163+ ) ;
164+ }
162165
163- super . _onReconnected ( ) ;
166+ if ( this . _database ) {
164167
165- } ) . then ( ( ) => {
168+ /**
169+ * Cache all imcoming commands before authentication completed.
170+ */
171+ this . _forcePipeline ( ) ;
166172
167- super . _onReconnected ( ) ;
168- } ) ;
173+ await this . executeNow (
174+ "SELECT" , this . _database . toString ( )
175+ ) ;
169176 }
170- else {
171177
172- super . _onReconnected ( ) ;
173- }
178+ return super . _onReconnected ( ) ;
174179 }
175180
176181 public async exists ( key : ItemKey ) : Promise < boolean > {
@@ -555,6 +560,8 @@ implements Abstract.RedisClient {
555560 public async select ( index : number ) : Promise < void > {
556561
557562 await this . execute < Buffer > ( "SELECT" , index . toString ( ) ) ;
563+
564+ this . _database = index ;
558565 }
559566
560567 public async swapDB ( db1 : number , db2 : number ) : Promise < void > {
0 commit comments