1
1
import COMMANDS from '../commands' ;
2
- import RedisSocket , { RedisSocketOptions , RedisTcpSocketOptions } from './socket' ;
2
+ import RedisSocket , { RedisSocketOptions } from './socket' ;
3
3
import { BasicAuth , CredentialsError , CredentialsProvider , StreamingCredentialsProvider , UnableToObtainNewCredentialsError , Disposable } from '../authx' ;
4
4
import RedisCommandsQueue , { CommandOptions } from './commands-queue' ;
5
5
import { EventEmitter } from 'node:events' ;
@@ -154,7 +154,7 @@ export interface RedisClientOptions<
154
154
*
155
155
* The default is `auto`.
156
156
*/
157
- maintPushNotifications ?: 'disabled' | 'enabled' | 'auto' ;
157
+ maintNotifications ?: 'disabled' | 'enabled' | 'auto' ;
158
158
/**
159
159
* Controls how the client requests the endpoint to reconnect to during a MOVING notification in Redis Enterprise maintenance.
160
160
*
@@ -167,19 +167,19 @@ export interface RedisClientOptions<
167
167
168
168
* The default is `auto`.
169
169
*/
170
- maintMovingEndpointType ?: MovingEndpointType ;
170
+ maintEndpointType ?: MovingEndpointType ;
171
171
/**
172
172
* Specifies a more relaxed timeout (in milliseconds) for commands during a maintenance window.
173
- * This helps minimize command timeouts during maintenance. If not provided, the `commandOptions.timeout`
174
- * will be used instead. Timeouts during maintenance period result in a `CommandTimeoutDuringMaintenance` error.
173
+ * This helps minimize command timeouts during maintenance. Timeouts during maintenance period result
174
+ * in a `CommandTimeoutDuringMaintenance` error.
175
175
*
176
176
* The default is 10000
177
177
*/
178
178
maintRelaxedCommandTimeout ?: number ;
179
179
/**
180
180
* Specifies a more relaxed timeout (in milliseconds) for the socket during a maintenance window.
181
- * This helps minimize socket timeouts during maintenance. If not provided, the `socket.timeout`
182
- * will be used instead. Timeouts during maintenance period result in a `SocketTimeoutDuringMaintenance` error.
181
+ * This helps minimize socket timeouts during maintenance. Timeouts during maintenance period result
182
+ * in a `SocketTimeoutDuringMaintenance` error.
183
183
*
184
184
* The default is 10000
185
185
*/
@@ -429,7 +429,7 @@ export default class RedisClient<
429
429
return parsed ;
430
430
}
431
431
432
- readonly #options? : RedisClientOptions < M , F , S , RESP , TYPE_MAPPING > ;
432
+ readonly #options: RedisClientOptions < M , F , S , RESP , TYPE_MAPPING > ;
433
433
#socket: RedisSocket ;
434
434
readonly #queue: RedisCommandsQueue ;
435
435
#selectedDB = 0 ;
@@ -453,7 +453,7 @@ export default class RedisClient<
453
453
return this . _self . #clientSideCache;
454
454
}
455
455
456
- get options ( ) : RedisClientOptions < M , F , S , RESP > | undefined {
456
+ get options ( ) : RedisClientOptions < M , F , S , RESP > {
457
457
return this . _self . #options;
458
458
}
459
459
@@ -503,15 +503,15 @@ export default class RedisClient<
503
503
this . #socket = this . #initiateSocket( ) ;
504
504
505
505
506
- if ( options ?. maintPushNotifications !== 'disabled' ) {
507
- new EnterpriseMaintenanceManager ( this . #queue, this , this . #options! ) ;
506
+ if ( this . # options. maintNotifications !== 'disabled' ) {
507
+ new EnterpriseMaintenanceManager ( this . #queue, this , this . #options) ;
508
508
} ;
509
509
510
- if ( options ? .clientSideCache ) {
511
- if ( options . clientSideCache instanceof ClientSideCacheProvider ) {
512
- this . #clientSideCache = options . clientSideCache ;
510
+ if ( this . # options. clientSideCache ) {
511
+ if ( this . # options. clientSideCache instanceof ClientSideCacheProvider ) {
512
+ this . #clientSideCache = this . # options. clientSideCache ;
513
513
} else {
514
- const cscConfig = options . clientSideCache ;
514
+ const cscConfig = this . # options. clientSideCache ;
515
515
this . #clientSideCache = new BasicClientSideCache ( cscConfig ) ;
516
516
}
517
517
this . #queue. addPushHandler ( ( push : Array < any > ) : boolean => {
@@ -535,16 +535,16 @@ export default class RedisClient<
535
535
throw new Error ( 'Client Side Caching is only supported with RESP3' ) ;
536
536
}
537
537
538
- if ( options ?. maintPushNotifications && options ?. maintPushNotifications !== 'disabled' && options ?. RESP !== 3 ) {
538
+ if ( options ?. maintNotifications && options ?. maintNotifications !== 'disabled' && options ?. RESP !== 3 ) {
539
539
throw new Error ( 'Graceful Maintenance is only supported with RESP3' ) ;
540
540
}
541
541
542
542
}
543
543
544
- #initiateOptions( options ? : RedisClientOptions < M , F , S , RESP , TYPE_MAPPING > ) : RedisClientOptions < M , F , S , RESP , TYPE_MAPPING > | undefined {
544
+ #initiateOptions( options : RedisClientOptions < M , F , S , RESP , TYPE_MAPPING > = { } ) : RedisClientOptions < M , F , S , RESP , TYPE_MAPPING > {
545
545
546
546
// Convert username/password to credentialsProvider if no credentialsProvider is already in place
547
- if ( ! options ? .credentialsProvider && ( options ? .username || options ? .password ) ) {
547
+ if ( ! options . credentialsProvider && ( options . username || options . password ) ) {
548
548
549
549
options . credentialsProvider = {
550
550
type : 'async-credentials-provider' ,
@@ -555,19 +555,19 @@ export default class RedisClient<
555
555
} ;
556
556
}
557
557
558
- if ( options ? .database ) {
558
+ if ( options . database ) {
559
559
this . _self . #selectedDB = options . database ;
560
560
}
561
561
562
- if ( options ? .commandOptions ) {
562
+ if ( options . commandOptions ) {
563
563
this . _commandOptions = options . commandOptions ;
564
564
}
565
565
566
- if ( options ?. maintPushNotifications !== 'disabled' ) {
567
- EnterpriseMaintenanceManager . setupDefaultMaintOptions ( options ! ) ;
566
+ if ( options . maintNotifications !== 'disabled' ) {
567
+ EnterpriseMaintenanceManager . setupDefaultMaintOptions ( options ) ;
568
568
}
569
569
570
- if ( options ? .url ) {
570
+ if ( options . url ) {
571
571
const parsedOptions = RedisClient . parseOptions ( options ) ;
572
572
if ( parsedOptions ?. database ) {
573
573
this . _self . #selectedDB = parsedOptions . database ;
@@ -580,8 +580,8 @@ export default class RedisClient<
580
580
581
581
#initiateQueue( ) : RedisCommandsQueue {
582
582
return new RedisCommandsQueue (
583
- this . #options? .RESP ?? 2 ,
584
- this . #options? .commandsQueueMaxLength ,
583
+ this . #options. RESP ?? 2 ,
584
+ this . #options. commandsQueueMaxLength ,
585
585
( channel , listeners ) => this . emit ( 'sharded-channel-moved' , channel , listeners )
586
586
) ;
587
587
}
@@ -591,7 +591,7 @@ export default class RedisClient<
591
591
*/
592
592
private reAuthenticate = async ( credentials : BasicAuth ) => {
593
593
// Re-authentication is not supported on RESP2 with PubSub active
594
- if ( ! ( this . isPubSubActive && ! this . #options? .RESP ) ) {
594
+ if ( ! ( this . isPubSubActive && ! this . #options. RESP ) ) {
595
595
await this . sendCommand (
596
596
parseArgs ( COMMANDS . AUTH , {
597
597
username : credentials . username ,
@@ -640,9 +640,9 @@ export default class RedisClient<
640
640
Array < { cmd : CommandArguments } & { errorHandler ?: ( err : Error ) => void } >
641
641
> {
642
642
const commands = [ ] ;
643
- const cp = this . #options? .credentialsProvider ;
643
+ const cp = this . #options. credentialsProvider ;
644
644
645
- if ( this . #options? .RESP ) {
645
+ if ( this . #options. RESP ) {
646
646
const hello : HelloOptions = { } ;
647
647
648
648
if ( cp && cp . type === 'async-credentials-provider' ) {
@@ -702,7 +702,7 @@ export default class RedisClient<
702
702
}
703
703
}
704
704
705
- if ( this . #options? .name ) {
705
+ if ( this . #options. name ) {
706
706
commands . push ( {
707
707
cmd : parseArgs ( COMMANDS . CLIENT_SETNAME , this . #options. name )
708
708
} ) ;
@@ -713,11 +713,11 @@ export default class RedisClient<
713
713
commands . push ( { cmd : [ 'SELECT' , this . #selectedDB. toString ( ) ] } ) ;
714
714
}
715
715
716
- if ( this . #options? .readonly ) {
716
+ if ( this . #options. readonly ) {
717
717
commands . push ( { cmd : parseArgs ( COMMANDS . READONLY ) } ) ;
718
718
}
719
719
720
- if ( ! this . #options? .disableClientInfo ) {
720
+ if ( ! this . #options. disableClientInfo ) {
721
721
commands . push ( {
722
722
cmd : [ 'CLIENT' , 'SETINFO' , 'LIB-VER' , version ] ,
723
723
errorHandler : ( ) => {
@@ -732,7 +732,7 @@ export default class RedisClient<
732
732
'CLIENT' ,
733
733
'SETINFO' ,
734
734
'LIB-NAME' ,
735
- this . #options? .clientInfoTag
735
+ this . #options. clientInfoTag
736
736
? `node-redis(${ this . #options. clientInfoTag } )`
737
737
: 'node-redis'
738
738
] ,
@@ -748,8 +748,7 @@ export default class RedisClient<
748
748
commands . push ( { cmd : this . #clientSideCache. trackingOn ( ) } ) ;
749
749
}
750
750
751
- const { tls, host } = this . #options! . socket as RedisTcpSocketOptions ;
752
- const maintenanceHandshakeCmd = await EnterpriseMaintenanceManager . getHandshakeCommand ( ! ! tls , host ! , this . #options! ) ;
751
+ const maintenanceHandshakeCmd = await EnterpriseMaintenanceManager . getHandshakeCommand ( this . #options) ;
753
752
if ( maintenanceHandshakeCmd ) {
754
753
commands . push ( maintenanceHandshakeCmd ) ;
755
754
} ;
@@ -769,7 +768,7 @@ export default class RedisClient<
769
768
. on ( 'error' , err => {
770
769
this . emit ( 'error' , err ) ;
771
770
this . #clientSideCache?. onError ( ) ;
772
- if ( this . #socket. isOpen && ! this . #options? .disableOfflineQueue ) {
771
+ if ( this . #socket. isOpen && ! this . #options. disableOfflineQueue ) {
773
772
this . #queue. flushWaitingForReply ( err ) ;
774
773
} else {
775
774
this . #queue. flushAll ( err ) ;
@@ -817,15 +816,15 @@ export default class RedisClient<
817
816
}
818
817
} ;
819
818
820
- const socket = new RedisSocket ( socketInitiator , this . #options? .socket ) ;
819
+ const socket = new RedisSocket ( socketInitiator , this . #options. socket ) ;
821
820
this . #attachListeners( socket ) ;
822
821
return socket ;
823
822
}
824
823
825
824
#pingTimer?: NodeJS . Timeout ;
826
825
827
826
#setPingTimer( ) : void {
828
- if ( ! this . #options? .pingInterval || ! this . #socket. isReady ) return ;
827
+ if ( ! this . #options. pingInterval || ! this . #socket. isReady ) return ;
829
828
clearTimeout ( this . #pingTimer) ;
830
829
831
830
this . #pingTimer = setTimeout ( ( ) => {
@@ -986,7 +985,7 @@ export default class RedisClient<
986
985
transformReply : TransformReply | undefined ,
987
986
) {
988
987
const csc = this . _self . #clientSideCache;
989
- const defaultTypeMapping = this . _self . #options? .commandOptions === commandOptions ;
988
+ const defaultTypeMapping = this . _self . #options. commandOptions === commandOptions ;
990
989
991
990
const fn = ( ) => { return this . sendCommand ( parser . redisArgs , commandOptions ) } ;
992
991
@@ -1035,7 +1034,7 @@ export default class RedisClient<
1035
1034
) : Promise < T > {
1036
1035
if ( ! this . _self . #socket. isOpen ) {
1037
1036
return Promise . reject ( new ClientClosedError ( ) ) ;
1038
- } else if ( ! this . _self . #socket. isReady && this . _self . #options? .disableOfflineQueue ) {
1037
+ } else if ( ! this . _self . #socket. isReady && this . _self . #options. disableOfflineQueue ) {
1039
1038
return Promise . reject ( new ClientOfflineError ( ) ) ;
1040
1039
}
1041
1040
0 commit comments