From 11b1b2c54a14b3a038e0437befcf68304d331741 Mon Sep 17 00:00:00 2001 From: Yuki Tanaka Date: Fri, 4 Dec 2020 19:49:33 +0900 Subject: [PATCH] chore: RedisSubscriptionImpl should not mutate Connection.maxRetryCount directly (#159) --- connection.ts | 10 ++++++++++ pubsub.ts | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/connection.ts b/connection.ts index b866ce45..a9d2a620 100644 --- a/connection.ts +++ b/connection.ts @@ -10,9 +10,11 @@ export interface Connection { retryInterval: number; isClosed: boolean; isConnected: boolean; + isRetriable: boolean; close(): void; connect(): Promise; reconnect(): Promise; + forceRetry(): void; } export type RedisConnectionOptions = { @@ -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, @@ -160,6 +166,10 @@ export class RedisConnection implements Connection { }); } } + + forceRetry(): void { + this.maxRetryCount = 10; // TODO Adjust this. + } } function parsePortLike(port: string | number | undefined): number { diff --git a/pubsub.ts b/pubsub.ts index 36b529bc..69eb66b9 100644 --- a/pubsub.ts +++ b/pubsub.ts @@ -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[]) {