Skip to content

Commit 1e40d55

Browse files
committed
refactor(client): #options cannot be undefined
1 parent 9614987 commit 1e40d55

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

packages/client/lib/client/index.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ export default class RedisClient<
453453
return this._self.#clientSideCache;
454454
}
455455

456-
get options(): RedisClientOptions<M, F, S, RESP> | undefined {
456+
get options(): RedisClientOptions<M, F, S, RESP> {
457457
return this._self.#options;
458458
}
459459

@@ -503,15 +503,15 @@ export default class RedisClient<
503503
this.#socket = this.#initiateSocket();
504504

505505

506-
if(options?.maintNotifications !== 'disabled') {
507-
new EnterpriseMaintenanceManager(this.#queue, this, this.#options!);
506+
if(this.#options.maintNotifications !== 'disabled') {
507+
new EnterpriseMaintenanceManager(this.#queue, this, this.#options);
508508
};
509509

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;
513513
} else {
514-
const cscConfig = options.clientSideCache;
514+
const cscConfig = this.#options.clientSideCache;
515515
this.#clientSideCache = new BasicClientSideCache(cscConfig);
516516
}
517517
this.#queue.addPushHandler((push: Array<any>): boolean => {
@@ -580,8 +580,8 @@ export default class RedisClient<
580580

581581
#initiateQueue(): RedisCommandsQueue {
582582
return new RedisCommandsQueue(
583-
this.#options?.RESP ?? 2,
584-
this.#options?.commandsQueueMaxLength,
583+
this.#options.RESP ?? 2,
584+
this.#options.commandsQueueMaxLength,
585585
(channel, listeners) => this.emit('sharded-channel-moved', channel, listeners)
586586
);
587587
}
@@ -591,7 +591,7 @@ export default class RedisClient<
591591
*/
592592
private reAuthenticate = async (credentials: BasicAuth) => {
593593
// Re-authentication is not supported on RESP2 with PubSub active
594-
if (!(this.isPubSubActive && !this.#options?.RESP)) {
594+
if (!(this.isPubSubActive && !this.#options.RESP)) {
595595
await this.sendCommand(
596596
parseArgs(COMMANDS.AUTH, {
597597
username: credentials.username,
@@ -640,9 +640,9 @@ export default class RedisClient<
640640
Array<{ cmd: CommandArguments } & { errorHandler?: (err: Error) => void }>
641641
> {
642642
const commands = [];
643-
const cp = this.#options?.credentialsProvider;
643+
const cp = this.#options.credentialsProvider;
644644

645-
if (this.#options?.RESP) {
645+
if (this.#options.RESP) {
646646
const hello: HelloOptions = {};
647647

648648
if (cp && cp.type === 'async-credentials-provider') {
@@ -702,7 +702,7 @@ export default class RedisClient<
702702
}
703703
}
704704

705-
if (this.#options?.name) {
705+
if (this.#options.name) {
706706
commands.push({
707707
cmd: parseArgs(COMMANDS.CLIENT_SETNAME, this.#options.name)
708708
});
@@ -713,11 +713,11 @@ export default class RedisClient<
713713
commands.push({ cmd: ['SELECT', this.#selectedDB.toString()] });
714714
}
715715

716-
if (this.#options?.readonly) {
716+
if (this.#options.readonly) {
717717
commands.push({ cmd: parseArgs(COMMANDS.READONLY) });
718718
}
719719

720-
if (!this.#options?.disableClientInfo) {
720+
if (!this.#options.disableClientInfo) {
721721
commands.push({
722722
cmd: ['CLIENT', 'SETINFO', 'LIB-VER', version],
723723
errorHandler: () => {
@@ -732,7 +732,7 @@ export default class RedisClient<
732732
'CLIENT',
733733
'SETINFO',
734734
'LIB-NAME',
735-
this.#options?.clientInfoTag
735+
this.#options.clientInfoTag
736736
? `node-redis(${this.#options.clientInfoTag})`
737737
: 'node-redis'
738738
],
@@ -768,7 +768,7 @@ export default class RedisClient<
768768
.on('error', err => {
769769
this.emit('error', err);
770770
this.#clientSideCache?.onError();
771-
if (this.#socket.isOpen && !this.#options?.disableOfflineQueue) {
771+
if (this.#socket.isOpen && !this.#options.disableOfflineQueue) {
772772
this.#queue.flushWaitingForReply(err);
773773
} else {
774774
this.#queue.flushAll(err);
@@ -816,15 +816,15 @@ export default class RedisClient<
816816
}
817817
};
818818

819-
const socket = new RedisSocket(socketInitiator, this.#options?.socket);
819+
const socket = new RedisSocket(socketInitiator, this.#options.socket);
820820
this.#attachListeners(socket);
821821
return socket;
822822
}
823823

824824
#pingTimer?: NodeJS.Timeout;
825825

826826
#setPingTimer(): void {
827-
if (!this.#options?.pingInterval || !this.#socket.isReady) return;
827+
if (!this.#options.pingInterval || !this.#socket.isReady) return;
828828
clearTimeout(this.#pingTimer);
829829

830830
this.#pingTimer = setTimeout(() => {
@@ -985,7 +985,7 @@ export default class RedisClient<
985985
transformReply: TransformReply | undefined,
986986
) {
987987
const csc = this._self.#clientSideCache;
988-
const defaultTypeMapping = this._self.#options?.commandOptions === commandOptions;
988+
const defaultTypeMapping = this._self.#options.commandOptions === commandOptions;
989989

990990
const fn = () => { return this.sendCommand(parser.redisArgs, commandOptions) };
991991

@@ -1034,7 +1034,7 @@ export default class RedisClient<
10341034
): Promise<T> {
10351035
if (!this._self.#socket.isOpen) {
10361036
return Promise.reject(new ClientClosedError());
1037-
} else if (!this._self.#socket.isReady && this._self.#options?.disableOfflineQueue) {
1037+
} else if (!this._self.#socket.isReady && this._self.#options.disableOfflineQueue) {
10381038
return Promise.reject(new ClientOfflineError());
10391039
}
10401040

0 commit comments

Comments
 (0)