diff --git a/built/cluster/ClusterSubscriber.js b/built/cluster/ClusterSubscriber.js index bf4e4bb..77a508c 100644 --- a/built/cluster/ClusterSubscriber.js +++ b/built/cluster/ClusterSubscriber.js @@ -33,6 +33,7 @@ class ClusterSubscriber { if (!this.started || !this.subscriber) { return; } + // @ts-expect-error if ((0, util_1.getNodeKey)(this.subscriber.options) === key) { debug("subscriber has left, selecting a new one..."); this.selectSubscriber(); @@ -63,6 +64,7 @@ class ClusterSubscriber { debug("stopped"); } selectSubscriber() { + var _a, _b; const lastActiveSubscriber = this.lastActiveSubscriber; // Disconnect the previous subscriber even if there // will not be a new one. @@ -116,13 +118,12 @@ class ClusterSubscriber { // Re-subscribe previous channels const previousChannels = { subscribe: [], psubscribe: [], ssubscribe: [] }; if (lastActiveSubscriber) { - const condition = lastActiveSubscriber.condition || lastActiveSubscriber.prevCondition; - if (condition && condition.subscriber) { - previousChannels.subscribe = condition.subscriber.channels("subscribe"); - previousChannels.psubscribe = - condition.subscriber.channels("psubscribe"); - previousChannels.ssubscribe = - condition.subscriber.channels("ssubscribe"); + const subscriber = ((_a = lastActiveSubscriber.condition) === null || _a === void 0 ? void 0 : _a.subscriber) || + ((_b = lastActiveSubscriber.prevCondition) === null || _b === void 0 ? void 0 : _b.subscriber); + if (subscriber) { + previousChannels.subscribe = subscriber.channels("subscribe"); + previousChannels.psubscribe = subscriber.channels("psubscribe"); + previousChannels.ssubscribe = subscriber.channels("ssubscribe"); } } if (previousChannels.subscribe.length || diff --git a/lib/cluster/ClusterSubscriber.ts b/lib/cluster/ClusterSubscriber.ts index e0ecd2e..05ea23b 100644 --- a/lib/cluster/ClusterSubscriber.ts +++ b/lib/cluster/ClusterSubscriber.ts @@ -3,13 +3,14 @@ import ConnectionPool from "./ConnectionPool"; import { getConnectionName, getNodeKey } from "./util"; import { sample, noop, Debug } from "../utils"; import Redis from "../Redis"; +import { Condition } from "../DataHandler"; const debug = Debug("cluster:subscriber"); export default class ClusterSubscriber { private started = false; - private subscriber: any = null; - private lastActiveSubscriber: any; + private subscriber: Redis | null = null; + private lastActiveSubscriber: Redis & { prevCondition?: Condition }; constructor( private connectionPool: ConnectionPool, @@ -27,6 +28,7 @@ export default class ClusterSubscriber { if (!this.started || !this.subscriber) { return; } + // @ts-expect-error if (getNodeKey(this.subscriber.options) === key) { debug("subscriber has left, selecting a new one..."); this.selectSubscriber(); @@ -140,14 +142,14 @@ export default class ClusterSubscriber { // Re-subscribe previous channels const previousChannels = { subscribe: [], psubscribe: [], ssubscribe: [] }; if (lastActiveSubscriber) { - const condition = - lastActiveSubscriber.condition || lastActiveSubscriber.prevCondition; - if (condition && condition.subscriber) { - previousChannels.subscribe = condition.subscriber.channels("subscribe"); - previousChannels.psubscribe = - condition.subscriber.channels("psubscribe"); - previousChannels.ssubscribe = - condition.subscriber.channels("ssubscribe"); + const subscriber = + lastActiveSubscriber.condition?.subscriber || + lastActiveSubscriber.prevCondition?.subscriber; + + if (subscriber) { + previousChannels.subscribe = subscriber.channels("subscribe"); + previousChannels.psubscribe = subscriber.channels("psubscribe"); + previousChannels.ssubscribe = subscriber.channels("ssubscribe"); } } if (