Skip to content

Commit 3fb2552

Browse files
imatlopezluin
authored andcommitted
fix: use connector as class not value (#909)
1 parent 7a62aec commit 3fb2552

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

examples/custom_connector.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class AsyncSentinelConnector extends Redis.SentinelConnector {
2323
}
2424

2525
const redis = new Redis({
26-
connector: new AsyncSentinelConnector()
26+
Connector: AsyncSentinelConnector
2727
});
2828

2929
// ioredis supports all Redis commands:

lib/redis/RedisOptions.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {ICommanderOptions} from '../commander';
66
export type ReconnectOnError = (err: Error) => boolean | 1 | 2;
77

88
export interface IRedisOptions extends Partial<ISentinelConnectionOptions>, Partial<ICommanderOptions>, Partial<IClusterOptions> {
9-
connector?: AbstractConnector,
9+
Connector?: typeof AbstractConnector,
1010
retryStrategy?: (times: number) => number | void | null,
1111
keepAlive?: number,
1212
noDelay?: boolean,

lib/redis/event_handler.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export function connectHandler(self) {
5454
}
5555
} else {
5656
self.serverInfo = info;
57-
if (self.options.connector.check(info)) {
57+
if (self.connector.check(info)) {
5858
exports.readyHandler(self)();
5959
} else {
6060
self.disconnect(true);

lib/redis/index.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,12 @@ function Redis() {
132132
this.resetCommandQueue();
133133
this.resetOfflineQueue();
134134

135-
if (!this.options.connector) {
136-
if (this.options.sentinels) {
137-
this.options.connector = new SentinelConnector(this.options);
138-
} else {
139-
this.options.connector = new StandaloneConnector(this.options);
140-
}
135+
if (this.options.Connector) {
136+
this.connector = new this.options.Connector(this.options);
137+
} else if (this.options.sentinels) {
138+
this.connector = new SentinelConnector(this.options);
139+
} else {
140+
this.connector = new StandaloneConnector(this.options);
141141
}
142142

143143
this.retryAttempts = 0;
@@ -251,7 +251,7 @@ Redis.prototype.connect = function (callback) {
251251
};
252252

253253
var _this = this;
254-
asCallback(options.connector.connect(function (type, err) {
254+
asCallback(this.connector.connect(function (type, err) {
255255
_this.silentEmit(type, err);
256256
}), function (err, stream) {
257257
if (err) {
@@ -345,7 +345,7 @@ Redis.prototype.disconnect = function (reconnect) {
345345
if (this.status === 'wait') {
346346
eventHandler.closeHandler(this)();
347347
} else {
348-
this.options.connector.disconnect();
348+
this.connector.disconnect();
349349
}
350350
};
351351

0 commit comments

Comments
 (0)