@@ -161,6 +161,12 @@ public static interface StrategySupplier {
161161 /** Default grace period in milliseconds to keep clusters disabled after they become unhealthy. */
162162 private static final long GRACE_PERIOD_DEFAULT = 10000 ;
163163
164+ /** Default maximum number of failover attempts. */
165+ private static final int MAX_NUM_FAILOVER_ATTEMPTS_DEFAULT = 10 ;
166+
167+ /** Default delay in milliseconds between failover attempts. */
168+ private static final int DELAY_IN_BETWEEN_FAILOVER_ATTEMPTS_DEFAULT = 12000 ;
169+
164170 /** Array of cluster configurations defining the available Redis endpoints and their settings. */
165171 private final ClusterConfig [] clusterConfigs ;
166172
@@ -485,6 +491,34 @@ public static interface StrategySupplier {
485491 */
486492 private boolean fastFailover ;
487493
494+ /**
495+ * Maximum number of failover attempts.
496+ * <p>
497+ * This setting controls how many times the system will attempt to failover to a different cluster
498+ * before giving up. For example, if set to 3, the system will make 1 initial attempt plus 2
499+ * failover attempts for a total of 3 attempts.
500+ * </p>
501+ * <p>
502+ * <strong>Default:</strong> {@value #MAX_NUM_FAILOVER_ATTEMPTS_DEFAULT}
503+ * </p>
504+ * @see #getMaxNumFailoverAttempts()
505+ */
506+ private int maxNumFailoverAttempts ;
507+
508+ /**
509+ * Delay in milliseconds between failover attempts.
510+ * <p>
511+ * This setting controls how long the system will wait before attempting to failover to a
512+ * different cluster. For example, if set to 1000, the system will wait 1 second before attempting
513+ * to failover to a different cluster.
514+ * </p>
515+ * <p>
516+ * <strong>Default:</strong> {@value #DELAY_IN_BETWEEN_FAILOVER_ATTEMPTS_DEFAULT} milliseconds
517+ * </p>
518+ * @see #getDelayInBetweenFailoverAttempts()
519+ */
520+ private int delayInBetweenFailoverAttempts ;
521+
488522 /**
489523 * Constructs a new MultiClusterClientConfig with the specified cluster configurations.
490524 * <p>
@@ -679,6 +713,25 @@ public long getGracePeriod() {
679713 return gracePeriod ;
680714 }
681715
716+ /**
717+ * Returns the maximum number of failover attempts.
718+ * @return maximum number of failover attempts
719+ * @see #maxNumFailoverAttempts
720+ */
721+ public int getMaxNumFailoverAttempts () {
722+ return maxNumFailoverAttempts ;
723+
724+ }
725+
726+ /**
727+ * Returns the delay in milliseconds between failover attempts.
728+ * @return delay in milliseconds between failover attempts
729+ * @see #delayInBetweenFailoverAttempts
730+ */
731+ public int getDelayInBetweenFailoverAttempts () {
732+ return delayInBetweenFailoverAttempts ;
733+ }
734+
682735 /**
683736 * Returns whether connections are forcefully terminated during failover.
684737 * @return true if fast failover is enabled, false for graceful failover
@@ -1090,6 +1143,12 @@ public static class Builder {
10901143 /** Whether to forcefully terminate connections during failover. */
10911144 private boolean fastFailover = false ;
10921145
1146+ /** Maximum number of failover attempts. */
1147+ private int maxNumFailoverAttempts = MAX_NUM_FAILOVER_ATTEMPTS_DEFAULT ;
1148+
1149+ /** Delay in milliseconds between failover attempts. */
1150+ private int delayInBetweenFailoverAttempts = DELAY_IN_BETWEEN_FAILOVER_ATTEMPTS_DEFAULT ;
1151+
10931152 /**
10941153 * Constructs a new Builder with the specified cluster configurations.
10951154 * @param clusterConfigs array of cluster configurations defining available Redis endpoints
@@ -1539,6 +1598,42 @@ public Builder fastFailover(boolean fastFailover) {
15391598 return this ;
15401599 }
15411600
1601+ /**
1602+ * Sets the maximum number of failover attempts.
1603+ * <p>
1604+ * This setting controls how many times the system will attempt to failover to a different
1605+ * cluster before giving up. For example, if set to 3, the system will make 1 initial attempt
1606+ * plus 2 failover attempts for a total of 3 attempts.
1607+ * </p>
1608+ * <p>
1609+ * <strong>Default:</strong> {@value #MAX_NUM_FAILOVER_ATTEMPTS_DEFAULT}
1610+ * </p>
1611+ * @param maxNumFailoverAttempts maximum number of failover attempts
1612+ * @return this builder instance for method chaining
1613+ */
1614+ public Builder maxNumFailoverAttempts (int maxNumFailoverAttempts ) {
1615+ this .maxNumFailoverAttempts = maxNumFailoverAttempts ;
1616+ return this ;
1617+ }
1618+
1619+ /**
1620+ * Sets the delay in milliseconds between failover attempts.
1621+ * <p>
1622+ * This setting controls how long the system will wait before attempting to failover to a
1623+ * different cluster. For example, if set to 1000, the system will wait 1 second before
1624+ * attempting to failover to a different cluster.
1625+ * </p>
1626+ * <p>
1627+ * <strong>Default:</strong> {@value #DELAY_IN_BETWEEN_FAILOVER_ATTEMPTS_DEFAULT} milliseconds
1628+ * </p>
1629+ * @param delayInBetweenFailoverAttempts delay in milliseconds between failover attempts
1630+ * @return this builder instance for method chaining
1631+ */
1632+ public Builder delayInBetweenFailoverAttempts (int delayInBetweenFailoverAttempts ) {
1633+ this .delayInBetweenFailoverAttempts = delayInBetweenFailoverAttempts ;
1634+ return this ;
1635+ }
1636+
15421637 /**
15431638 * Builds and returns a new MultiClusterClientConfig instance with all configured settings.
15441639 * <p>
@@ -1576,6 +1671,8 @@ public MultiClusterClientConfig build() {
15761671 config .failbackCheckInterval = this .failbackCheckInterval ;
15771672 config .gracePeriod = this .gracePeriod ;
15781673 config .fastFailover = this .fastFailover ;
1674+ config .maxNumFailoverAttempts = this .maxNumFailoverAttempts ;
1675+ config .delayInBetweenFailoverAttempts = this .delayInBetweenFailoverAttempts ;
15791676
15801677 return config ;
15811678 }
0 commit comments