Skip to content

Commit 5f00576

Browse files
authored
[automatic failover] Replace EchoStrategy with PingStrategy (#4313)
* - replace EchoStrategy with PingStrategy * - fix doc
1 parent 6a4a94b commit 5f00576

File tree

9 files changed

+52
-53
lines changed

9 files changed

+52
-53
lines changed

.github/wordlist.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ CRDB
2323
Dockerfile
2424
EVAL
2525
EVALSHA
26-
EchoStrategy
2726
FTCreateParams
2827
FTSearchParams
2928
Failback
@@ -71,6 +70,7 @@ OpenCensus
7170
OpenTelemetry
7271
OpenTracing
7372
Otel
73+
PingStrategy
7474
POJO
7575
POJOs
7676
PoolConfig

docs/failover.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,18 +159,18 @@ The health check system operates independently of your application traffic, runn
159159

160160
#### Available Health Check Types
161161

162-
##### 1. EchoStrategy (Default)
162+
##### 1. PingStrategy (Default)
163163

164-
The `EchoStrategy` is the default health check implementation that uses Redis's `ECHO` command to verify both connectivity and write capability.
164+
The `PingStrategy` is the default health check implementation that uses Redis's `PING` command to verify both connectivity and write capability.
165165

166166
**Use Cases:**
167167
- General-purpose health checking for most Redis deployments
168168
- Verifying both read and write operations
169169
- Simple connectivity validation
170170

171171
**How it works:**
172-
- Sends `ECHO "HealthCheck"` command to the Redis server
173-
- Expects exact response `"HealthCheck"` to consider the server healthy
172+
- Sends `PING` command to the Redis server
173+
- Expects exact response `"PONG"` to consider the server healthy
174174
- Any exception or unexpected response marks the server as unhealthy
175175

176176
##### 2. LagAwareStrategy [PREVIEW] (Redis Enterprise)

src/main/java/redis/clients/jedis/MultiDbConfig.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import redis.clients.jedis.exceptions.JedisConnectionException;
1212
import redis.clients.jedis.exceptions.JedisValidationException;
1313
import redis.clients.jedis.mcf.ConnectionFailoverException;
14-
import redis.clients.jedis.mcf.EchoStrategy;
14+
import redis.clients.jedis.mcf.PingStrategy;
1515
import redis.clients.jedis.mcf.HealthCheckStrategy;
1616

1717
/**
@@ -71,7 +71,7 @@
7171
* </p>
7272
* @see redis.clients.jedis.mcf.MultiDbConnectionProvider
7373
* @see redis.clients.jedis.mcf.HealthCheckStrategy
74-
* @see redis.clients.jedis.mcf.EchoStrategy
74+
* @see redis.clients.jedis.mcf.PingStrategy
7575
* @see redis.clients.jedis.mcf.LagAwareStrategy
7676
* @since 7.0
7777
*/
@@ -90,13 +90,13 @@ public final class MultiDbConfig {
9090
* <strong>Common Implementations:</strong>
9191
* </p>
9292
* <ul>
93-
* <li>{@link redis.clients.jedis.mcf.EchoStrategy#DEFAULT} - Uses Redis ECHO command for health
93+
* <li>{@link redis.clients.jedis.mcf.PingStrategy#DEFAULT} - Uses Redis PING command for health
9494
* checks</li>
9595
* <li>Custom implementations for specific monitoring requirements</li>
9696
* <li>Redis Enterprise implementations using REST API monitoring</li>
9797
* </ul>
9898
* @see redis.clients.jedis.mcf.HealthCheckStrategy
99-
* @see redis.clients.jedis.mcf.EchoStrategy
99+
* @see redis.clients.jedis.mcf.PingStrategy
100100
* @see redis.clients.jedis.mcf.LagAwareStrategy
101101
*/
102102
public static interface StrategySupplier {
@@ -839,15 +839,15 @@ public static class DatabaseConfig {
839839

840840
/**
841841
* Strategy supplier for creating health check instances for this database. Default is
842-
* EchoStrategy.DEFAULT.
842+
* PingStrategy.DEFAULT.
843843
*/
844844
private StrategySupplier healthCheckStrategySupplier;
845845

846846
/**
847847
* Constructs a DatabaseConfig with basic endpoint and client configuration.
848848
* <p>
849849
* This constructor creates a database configuration with default settings: weight of 1.0f and
850-
* EchoStrategy for health checks. Use the {@link Builder} for more advanced configuration
850+
* PingStrategy for health checks. Use the {@link Builder} for more advanced configuration
851851
* options.
852852
* </p>
853853
* @param endpoint the Redis endpoint (host and port)
@@ -863,7 +863,7 @@ public DatabaseConfig(Endpoint endpoint, JedisClientConfig clientConfig) {
863863
* Constructs a DatabaseConfig with endpoint, client, and connection pool configuration.
864864
* <p>
865865
* This constructor allows specification of connection pool settings in addition to basic
866-
* endpoint configuration. Default weight of 1.0f and EchoStrategy for health checks are used.
866+
* endpoint configuration. Default weight of 1.0f and PingStrategy for health checks are used.
867867
* </p>
868868
* @param endpoint the Redis endpoint (host and port)
869869
* @param clientConfig the Jedis client configuration
@@ -963,7 +963,7 @@ public StrategySupplier getHealthCheckStrategySupplier() {
963963
* </p>
964964
* <ul>
965965
* <li><strong>Weight:</strong> 1.0f (standard priority)</li>
966-
* <li><strong>Health Check:</strong> {@link redis.clients.jedis.mcf.EchoStrategy#DEFAULT}</li>
966+
* <li><strong>Health Check:</strong> {@link redis.clients.jedis.mcf.PingStrategy#DEFAULT}</li>
967967
* <li><strong>Connection Pool:</strong> null (uses default pooling)</li>
968968
* </ul>
969969
*/
@@ -980,8 +980,8 @@ public static class Builder {
980980
/** Weight for database selection priority. Default: 1.0f */
981981
private float weight = 1.0f;
982982

983-
/** Health check strategy supplier. Default: EchoStrategy.DEFAULT */
984-
private StrategySupplier healthCheckStrategySupplier = EchoStrategy.DEFAULT;
983+
/** Health check strategy supplier. Default: PingStrategy.DEFAULT */
984+
private StrategySupplier healthCheckStrategySupplier = PingStrategy.DEFAULT;
985985

986986
/**
987987
* Constructs a new Builder with required endpoint and client configuration.
@@ -1089,7 +1089,7 @@ public Builder healthCheckStrategy(HealthCheckStrategy healthCheckStrategy) {
10891089
* </ul>
10901090
* <p>
10911091
* When health checks are enabled (true) and no strategy supplier was previously set, the
1092-
* default {@link redis.clients.jedis.mcf.EchoStrategy#DEFAULT} will be used.
1092+
* default {@link redis.clients.jedis.mcf.PingStrategy#DEFAULT} will be used.
10931093
* </p>
10941094
* @param healthCheckEnabled true to enable health checks, false to disable
10951095
* @return this builder instance for method chaining
@@ -1098,7 +1098,7 @@ public Builder healthCheckEnabled(boolean healthCheckEnabled) {
10981098
if (!healthCheckEnabled) {
10991099
this.healthCheckStrategySupplier = null;
11001100
} else if (healthCheckStrategySupplier == null) {
1101-
this.healthCheckStrategySupplier = EchoStrategy.DEFAULT;
1101+
this.healthCheckStrategySupplier = PingStrategy.DEFAULT;
11021102
}
11031103
return this;
11041104
}

src/main/java/redis/clients/jedis/mcf/EchoStrategy.java renamed to src/main/java/redis/clients/jedis/mcf/PingStrategy.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@
1010
import redis.clients.jedis.UnifiedJedis;
1111
import redis.clients.jedis.MultiDbConfig.StrategySupplier;
1212

13-
public class EchoStrategy implements HealthCheckStrategy {
13+
public class PingStrategy implements HealthCheckStrategy {
1414
private static final int MAX_HEALTH_CHECK_POOL_SIZE = 2;
1515

1616
private final UnifiedJedis jedis;
1717
private final HealthCheckStrategy.Config config;
1818

19-
public EchoStrategy(HostAndPort hostAndPort, JedisClientConfig jedisClientConfig) {
19+
public PingStrategy(HostAndPort hostAndPort, JedisClientConfig jedisClientConfig) {
2020
this(hostAndPort, jedisClientConfig, HealthCheckStrategy.Config.create());
2121
}
2222

23-
public EchoStrategy(HostAndPort hostAndPort, JedisClientConfig jedisClientConfig,
23+
public PingStrategy(HostAndPort hostAndPort, JedisClientConfig jedisClientConfig,
2424
HealthCheckStrategy.Config config) {
2525
GenericObjectPoolConfig<Connection> poolConfig = new GenericObjectPoolConfig<>();
2626
poolConfig.setMaxTotal(MAX_HEALTH_CHECK_POOL_SIZE);
@@ -55,15 +55,14 @@ public int getDelayInBetweenProbes() {
5555

5656
@Override
5757
public HealthStatus doHealthCheck(Endpoint endpoint) {
58-
return "HealthCheck".equals(jedis.echo("HealthCheck")) ? HealthStatus.HEALTHY
59-
: HealthStatus.UNHEALTHY;
58+
return "PONG".equals(jedis.ping()) ? HealthStatus.HEALTHY : HealthStatus.UNHEALTHY;
6059
}
6160

6261
@Override
6362
public void close() {
6463
jedis.close();
6564
}
6665

67-
public static final StrategySupplier DEFAULT = EchoStrategy::new;
66+
public static final StrategySupplier DEFAULT = PingStrategy::new;
6867

6968
}

src/test/java/redis/clients/jedis/mcf/DefaultValuesTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ void testDefaultValuesInConfig() {
3333
// check healthchecks enabled
3434
assertNotNull(databaseConfig.getHealthCheckStrategySupplier());
3535

36-
// check default healthcheck strategy is echo
37-
assertEquals(EchoStrategy.DEFAULT, databaseConfig.getHealthCheckStrategySupplier());
36+
// check default healthcheck strategy is PingStrategy
37+
assertEquals(PingStrategy.DEFAULT, databaseConfig.getHealthCheckStrategySupplier());
3838

3939
// check number of probes
4040
assertEquals(3,

src/test/java/redis/clients/jedis/mcf/HealthCheckIntegrationTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ public void testDisableHealthCheck() {
4242

4343
@Test
4444
public void testDefaultStrategySupplier() {
45-
// Create a default strategy supplier that creates EchoStrategy instances
45+
// Create a default strategy supplier that creates PingStrategy instances
4646
MultiDbConfig.StrategySupplier defaultSupplier = (hostAndPort, jedisClientConfig) -> {
47-
return new EchoStrategy(hostAndPort, jedisClientConfig);
47+
return new PingStrategy(hostAndPort, jedisClientConfig);
4848
};
4949
MultiDbConnectionProvider customProvider = getMCCF(defaultSupplier);
5050
try (UnifiedJedis customClient = new UnifiedJedis(customProvider)) {
@@ -113,8 +113,8 @@ public void testProbingLogic_RealHealthCheckWithProbes() throws InterruptedExcep
113113
}
114114
// Third attempt succeeds - do actual health check
115115
try (UnifiedJedis jedis = new UnifiedJedis(hostAndPort, jedisClientConfig)) {
116-
String result = jedis.echo("HealthCheck");
117-
return "HealthCheck".equals(result) ? HealthStatus.HEALTHY : HealthStatus.UNHEALTHY;
116+
String result = jedis.ping();
117+
return "PONG".equals(result) ? HealthStatus.HEALTHY : HealthStatus.UNHEALTHY;
118118
} catch (Exception e) {
119119
return HealthStatus.UNHEALTHY;
120120
}

src/test/java/redis/clients/jedis/mcf/HealthCheckTest.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -321,11 +321,11 @@ void testHealthStatusManagerClose() {
321321
verify(closeableStrategy).close();
322322
}
323323

324-
// ========== EchoStrategy Tests ==========
324+
// ========== PingStrategy Tests ==========
325325

326326
@Test
327-
void testEchoStrategyCustomIntervalTimeout() {
328-
try (EchoStrategy strategy = new EchoStrategy(testEndpoint, testConfig,
327+
void testPingStrategyCustomIntervalTimeout() {
328+
try (PingStrategy strategy = new PingStrategy(testEndpoint, testConfig,
329329
HealthCheckStrategy.Config.builder().interval(2000).timeout(1500).delayInBetweenProbes(50)
330330
.numProbes(11).policy(BuiltIn.ANY_SUCCESS).build())) {
331331
assertEquals(2000, strategy.getInterval());
@@ -337,11 +337,11 @@ void testEchoStrategyCustomIntervalTimeout() {
337337
}
338338

339339
@Test
340-
void testEchoStrategyDefaultSupplier() {
341-
MultiDbConfig.StrategySupplier supplier = EchoStrategy.DEFAULT;
340+
void testPingStrategyDefaultSupplier() {
341+
MultiDbConfig.StrategySupplier supplier = PingStrategy.DEFAULT;
342342
HealthCheckStrategy strategy = supplier.get(testEndpoint, testConfig);
343343

344-
assertInstanceOf(EchoStrategy.class, strategy);
344+
assertInstanceOf(PingStrategy.class, strategy);
345345
}
346346

347347
// ========== Failover configuration Tests ==========
@@ -368,7 +368,7 @@ void testDefaultValues() {
368368
.builder(testEndpoint, testConfig).build();
369369

370370
assertEquals(1.0f, databaseConfig.getWeight()); // Default weight
371-
assertEquals(EchoStrategy.DEFAULT, databaseConfig.getHealthCheckStrategySupplier()); // Default
371+
assertEquals(PingStrategy.DEFAULT, databaseConfig.getHealthCheckStrategySupplier()); // Default
372372
// is null
373373
// (no
374374
// health
@@ -410,26 +410,26 @@ void testDatabaseConfigWithStrategySupplier() {
410410
}
411411

412412
@Test
413-
void testDatabaseConfigWithEchoStrategy() {
414-
MultiDbConfig.StrategySupplier echoSupplier = (hostAndPort, jedisClientConfig) -> {
415-
return new EchoStrategy(hostAndPort, jedisClientConfig);
413+
void testDatabaseConfigWithPingStrategy() {
414+
MultiDbConfig.StrategySupplier pingSupplier = (hostAndPort, jedisClientConfig) -> {
415+
return new PingStrategy(hostAndPort, jedisClientConfig);
416416
};
417417

418418
MultiDbConfig.DatabaseConfig databaseConfig = MultiDbConfig.DatabaseConfig
419-
.builder(testEndpoint, testConfig).healthCheckStrategySupplier(echoSupplier).build();
419+
.builder(testEndpoint, testConfig).healthCheckStrategySupplier(pingSupplier).build();
420420

421421
MultiDbConfig.StrategySupplier supplier = databaseConfig.getHealthCheckStrategySupplier();
422422
assertNotNull(supplier);
423-
assertInstanceOf(EchoStrategy.class, supplier.get(testEndpoint, testConfig));
423+
assertInstanceOf(PingStrategy.class, supplier.get(testEndpoint, testConfig));
424424
}
425425

426426
@Test
427427
void testDatabaseConfigWithDefaultHealthCheck() {
428428
MultiDbConfig.DatabaseConfig databaseConfig = MultiDbConfig.DatabaseConfig
429-
.builder(testEndpoint, testConfig).build(); // Should use default EchoStrategy
429+
.builder(testEndpoint, testConfig).build(); // Should use default PingStrategy
430430

431431
assertNotNull(databaseConfig.getHealthCheckStrategySupplier());
432-
assertEquals(EchoStrategy.DEFAULT, databaseConfig.getHealthCheckStrategySupplier());
432+
assertEquals(PingStrategy.DEFAULT, databaseConfig.getHealthCheckStrategySupplier());
433433
}
434434

435435
@Test
@@ -446,7 +446,7 @@ void testDatabaseConfigHealthCheckEnabledExplicitly() {
446446
.builder(testEndpoint, testConfig).healthCheckEnabled(true).build();
447447

448448
assertNotNull(databaseConfig.getHealthCheckStrategySupplier());
449-
assertEquals(EchoStrategy.DEFAULT, databaseConfig.getHealthCheckStrategySupplier());
449+
assertEquals(PingStrategy.DEFAULT, databaseConfig.getHealthCheckStrategySupplier());
450450
}
451451

452452
// ========== Integration Tests ==========
@@ -516,10 +516,10 @@ void testStrategySupplierPolymorphism() {
516516
// Test that the polymorphic design works correctly
517517
MultiDbConfig.StrategySupplier supplier = (hostAndPort, jedisClientConfig) -> {
518518
if (jedisClientConfig != null) {
519-
return new EchoStrategy(hostAndPort, jedisClientConfig,
519+
return new PingStrategy(hostAndPort, jedisClientConfig,
520520
HealthCheckStrategy.Config.builder().interval(500).timeout(250).numProbes(1).build());
521521
} else {
522-
return new EchoStrategy(hostAndPort, DefaultJedisClientConfig.builder().build());
522+
return new PingStrategy(hostAndPort, DefaultJedisClientConfig.builder().build());
523523
}
524524
};
525525

src/test/java/redis/clients/jedis/mcf/MultiDbConnectionProviderInitializationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void testInitializationWithMixedHealthCheckConfiguration() {
5656
.build();
5757

5858
DatabaseConfig db2 = DatabaseConfig.builder(endpoint2, clientConfig).weight(2.0f)
59-
.healthCheckStrategySupplier(EchoStrategy.DEFAULT) // With
59+
.healthCheckStrategySupplier(PingStrategy.DEFAULT) // With
6060
// health
6161
// check
6262
.build();

src/test/java/redis/clients/jedis/mcf/EchoStrategyIntegrationTest.java renamed to src/test/java/redis/clients/jedis/mcf/PingStrategyIntegrationTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import static org.junit.jupiter.api.Assertions.*;
2121

2222
@Tag("failover")
23-
public class EchoStrategyIntegrationTest {
23+
public class PingStrategyIntegrationTest {
2424

2525
private static final EndpointConfig endpoint = HostAndPorts.getRedisEndpoint("redis-failover-1");
2626
private static final HostAndPort proxyHostAndPort = endpoint.getHostAndPort();
@@ -55,10 +55,10 @@ public void resetProxy() throws IOException {
5555
}
5656

5757
@Test
58-
public void testEchoStrategyRecoversAfterDisconnect() throws Exception {
58+
public void testPingStrategyRecoversAfterDisconnect() throws Exception {
5959
JedisClientConfig config = DefaultJedisClientConfig.builder().socketTimeoutMillis(1000)
6060
.connectionTimeoutMillis(1000).build();
61-
try (EchoStrategy strategy = new EchoStrategy(proxyHostAndPort, config,
61+
try (PingStrategy strategy = new PingStrategy(proxyHostAndPort, config,
6262
HealthCheckStrategy.Config.create())) {
6363

6464
// Initial health check should work
@@ -81,11 +81,11 @@ public void testEchoStrategyRecoversAfterDisconnect() throws Exception {
8181
}
8282

8383
@Test
84-
public void testEchoStrategyWithConnectionTimeout() throws Exception {
84+
public void testPingStrategyWithConnectionTimeout() throws Exception {
8585
JedisClientConfig config = DefaultJedisClientConfig.builder().socketTimeoutMillis(100)
8686
.connectionTimeoutMillis(100).build();
8787

88-
try (EchoStrategy strategy = new EchoStrategy(proxyHostAndPort, config,
88+
try (PingStrategy strategy = new PingStrategy(proxyHostAndPort, config,
8989
HealthCheckStrategy.Config.builder().interval(1000).timeout(500).numProbes(1).build())) {
9090

9191
// Initial health check should work
@@ -110,7 +110,7 @@ public void testEchoStrategyWithConnectionTimeout() throws Exception {
110110
@Test
111111
public void testConnectionDropDuringHealthCheck() throws Exception {
112112
JedisClientConfig config = DefaultJedisClientConfig.builder().socketTimeoutMillis(2000).build();
113-
try (EchoStrategy strategy = new EchoStrategy(proxyHostAndPort, config,
113+
try (PingStrategy strategy = new PingStrategy(proxyHostAndPort, config,
114114
HealthCheckStrategy.Config.create())) {
115115

116116
// Initial health check

0 commit comments

Comments
 (0)