Skip to content

Commit

Permalink
chore: RedisSubscriptionImpl should not mutate Connection.maxRetryCou…
Browse files Browse the repository at this point in the history
…nt directly (#159)
  • Loading branch information
uki00a authored Dec 4, 2020
1 parent 0260475 commit 11b1b2c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ export interface Connection {
retryInterval: number;
isClosed: boolean;
isConnected: boolean;
isRetriable: boolean;
close(): void;
connect(): Promise<void>;
reconnect(): Promise<void>;
forceRetry(): void;
}

export type RedisConnectionOptions = {
Expand Down Expand Up @@ -45,6 +47,10 @@ export class RedisConnection implements Connection {
return this._isConnected;
}

get isRetriable(): boolean {
return this.maxRetryCount > 0;
}

constructor(
hostname: string,
port: number | string,
Expand Down Expand Up @@ -160,6 +166,10 @@ export class RedisConnection implements Connection {
});
}
}

forceRetry(): void {
this.maxRetryCount = 10; // TODO Adjust this.
}
}

function parsePortLike(port: string | number | undefined): number {
Expand Down
2 changes: 1 addition & 1 deletion pubsub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class RedisSubscriptionImpl implements RedisSubscription {

constructor(private connection: Connection) {
// Force retriable connection for connection shared for pub/sub.
if (connection.maxRetryCount === 0) connection.maxRetryCount = 10;
if (!connection.isRetriable) connection.forceRetry();
}

async psubscribe(...patterns: string[]) {
Expand Down

0 comments on commit 11b1b2c

Please sign in to comment.