Skip to content

Commit

Permalink
fix: use connector as class not value (#909)
Browse files Browse the repository at this point in the history
  • Loading branch information
imatlopez authored and luin committed Jun 26, 2019
1 parent 7a62aec commit 3fb2552
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion examples/custom_connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class AsyncSentinelConnector extends Redis.SentinelConnector {
}

const redis = new Redis({
connector: new AsyncSentinelConnector()
Connector: AsyncSentinelConnector
});

// ioredis supports all Redis commands:
Expand Down
2 changes: 1 addition & 1 deletion lib/redis/RedisOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {ICommanderOptions} from '../commander';
export type ReconnectOnError = (err: Error) => boolean | 1 | 2;

export interface IRedisOptions extends Partial<ISentinelConnectionOptions>, Partial<ICommanderOptions>, Partial<IClusterOptions> {
connector?: AbstractConnector,
Connector?: typeof AbstractConnector,
retryStrategy?: (times: number) => number | void | null,
keepAlive?: number,
noDelay?: boolean,
Expand Down
2 changes: 1 addition & 1 deletion lib/redis/event_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 8 additions & 8 deletions lib/redis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -345,7 +345,7 @@ Redis.prototype.disconnect = function (reconnect) {
if (this.status === 'wait') {
eventHandler.closeHandler(this)();
} else {
this.options.connector.disconnect();
this.connector.disconnect();
}
};

Expand Down

0 comments on commit 3fb2552

Please sign in to comment.