From 3fb2552115cce294f387ff39780ecf50b092a758 Mon Sep 17 00:00:00 2001 From: Matias Lopez Date: Tue, 25 Jun 2019 23:40:36 -0400 Subject: [PATCH] fix: use connector as class not value (#909) --- examples/custom_connector.js | 2 +- lib/redis/RedisOptions.ts | 2 +- lib/redis/event_handler.ts | 2 +- lib/redis/index.ts | 16 ++++++++-------- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/examples/custom_connector.js b/examples/custom_connector.js index fbe811fe..b9d581d0 100644 --- a/examples/custom_connector.js +++ b/examples/custom_connector.js @@ -23,7 +23,7 @@ class AsyncSentinelConnector extends Redis.SentinelConnector { } const redis = new Redis({ - connector: new AsyncSentinelConnector() + Connector: AsyncSentinelConnector }); // ioredis supports all Redis commands: diff --git a/lib/redis/RedisOptions.ts b/lib/redis/RedisOptions.ts index 8581faf6..b4217dde 100644 --- a/lib/redis/RedisOptions.ts +++ b/lib/redis/RedisOptions.ts @@ -6,7 +6,7 @@ import {ICommanderOptions} from '../commander'; export type ReconnectOnError = (err: Error) => boolean | 1 | 2; export interface IRedisOptions extends Partial, Partial, Partial { - connector?: AbstractConnector, + Connector?: typeof AbstractConnector, retryStrategy?: (times: number) => number | void | null, keepAlive?: number, noDelay?: boolean, diff --git a/lib/redis/event_handler.ts b/lib/redis/event_handler.ts index 35d1218d..90734a67 100644 --- a/lib/redis/event_handler.ts +++ b/lib/redis/event_handler.ts @@ -54,7 +54,7 @@ export function connectHandler(self) { } } else { self.serverInfo = info; - if (self.options.connector.check(info)) { + if (self.connector.check(info)) { exports.readyHandler(self)(); } else { self.disconnect(true); diff --git a/lib/redis/index.ts b/lib/redis/index.ts index 7b283da5..1442da46 100644 --- a/lib/redis/index.ts +++ b/lib/redis/index.ts @@ -132,12 +132,12 @@ function Redis() { this.resetCommandQueue(); this.resetOfflineQueue(); - if (!this.options.connector) { - if (this.options.sentinels) { - this.options.connector = new SentinelConnector(this.options); - } else { - this.options.connector = new StandaloneConnector(this.options); - } + if (this.options.Connector) { + this.connector = new this.options.Connector(this.options); + } else if (this.options.sentinels) { + this.connector = new SentinelConnector(this.options); + } else { + this.connector = new StandaloneConnector(this.options); } this.retryAttempts = 0; @@ -251,7 +251,7 @@ Redis.prototype.connect = function (callback) { }; var _this = this; - asCallback(options.connector.connect(function (type, err) { + asCallback(this.connector.connect(function (type, err) { _this.silentEmit(type, err); }), function (err, stream) { if (err) { @@ -345,7 +345,7 @@ Redis.prototype.disconnect = function (reconnect) { if (this.status === 'wait') { eventHandler.closeHandler(this)(); } else { - this.options.connector.disconnect(); + this.connector.disconnect(); } };