Skip to content

Commit

Permalink
fix(SENTINEL): actively failover detection under an option (#1363)
Browse files Browse the repository at this point in the history
  • Loading branch information
luin authored Jun 5, 2021
1 parent c87ea2a commit f02e383
Show file tree
Hide file tree
Showing 4 changed files with 212 additions and 196 deletions.
4 changes: 4 additions & 0 deletions lib/connectors/SentinelConnector/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export interface ISentinelConnectionOptions extends ITcpConnectionOptions {
natMap?: INatMap;
updateSentinels?: boolean;
sentinelMaxConnections?: number;
failoverDetector?: boolean;
}

export default class SentinelConnector extends AbstractConnector {
Expand Down Expand Up @@ -321,6 +322,9 @@ export default class SentinelConnector extends AbstractConnector {
}

private async initFailoverDetector(): Promise<void> {
if (!this.options.failoverDetector) {
return;
}
// Move the current sentinel to the first position
this.sentinelIterator.reset(true);

Expand Down
1 change: 1 addition & 0 deletions lib/redis/RedisOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export const DEFAULT_REDIS_OPTIONS: IRedisOptions = {
natMap: null,
enableTLSForSentinelMode: false,
updateSentinels: true,
failoverDetector: false,
// Status
username: null,
password: null,
Expand Down
5 changes: 5 additions & 0 deletions lib/redis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ const debug = Debug("redis");
* @param {NatMap} [options.natMap=null] NAT map for sentinel connector.
* @param {boolean} [options.updateSentinels=true] - Update the given `sentinels` list with new IP
* addresses when communicating with existing sentinels.
* @param {boolean} [options.failoverDetector=false] - Detect failover actively by subscribing to the
* related channels. With this option disabled, ioredis is still able to detect failovers because Redis
* Sentinel will disconnect all clients whenever a failover happens, so ioredis will reconnect to the new
* master. This option is useful when you want to detect failover quicker, but it will create more TCP
* connections to Redis servers in order to subscribe to related channels.
* @param {boolean} [options.enableAutoPipelining=false] - When enabled, all commands issued during an event loop
* iteration are automatically wrapped in a pipeline and sent to the server at the same time.
* This can dramatically improve performance.
Expand Down
Loading

0 comments on commit f02e383

Please sign in to comment.