Skip to content

Commit

Permalink
fix: let null password not fail health check
Browse files Browse the repository at this point in the history
  • Loading branch information
Lambert-Rao committed Apr 18, 2024
1 parent 0a2a03c commit 32e4170
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
@HealthCheckType(type = HealthCheckTypeConstant.HEALTH_CHECK_TYPE_STORAGE, subType = HealthCheckTypeConstant.HEALTH_CHECK_SUBTYPE_REDIS)
public class RedisCheck extends AbstractHealthCheckService {

private CreateRedisConfig config;
private CreateRedisConfig sdkConfig;

public RedisCheck(HealthCheckObjectConfig healthCheckObjectConfig) {
super(healthCheckObjectConfig);
Expand All @@ -50,7 +50,7 @@ public RedisCheck(HealthCheckObjectConfig healthCheckObjectConfig) {
public void doCheck(HealthCheckCallback callback) {
try {
StatefulRedisConnection<String, String> connection = (StatefulRedisConnection<String, String>) SDKManager.getInstance()
.getClient(SDKTypeEnum.STORAGE_REDIS, config.getUniqueKey());
.getClient(SDKTypeEnum.STORAGE_REDIS, sdkConfig.getUniqueKey());
RedisAsyncCommands<String, String> commands = connection.async();
commands.ping().thenAccept(result -> {
callback.onSuccess();
Expand All @@ -71,7 +71,7 @@ public void doCheck(HealthCheckCallback callback) {
@Override
public void init() {
String redisUrl;
config = new CreateRedisConfig();
sdkConfig = new CreateRedisConfig();
if (Objects.nonNull(getConfig().getConnectUrl()) && !getConfig().getConnectUrl().isEmpty()) {
redisUrl = getConfig().getConnectUrl();
} else {
Expand All @@ -87,12 +87,12 @@ public void init() {
}
redisUrl = builder.build().toString();
}
config.setRedisUrl(redisUrl);
SDKManager.getInstance().createClient(SDKTypeEnum.STORAGE_REDIS, config);
sdkConfig.setRedisUrl(redisUrl);
SDKManager.getInstance().createClient(SDKTypeEnum.STORAGE_REDIS, sdkConfig);
}

@Override
public void destroy() {
SDKManager.getInstance().deleteClient(SDKTypeEnum.STORAGE_REDIS, config.getUniqueKey());
SDKManager.getInstance().deleteClient(SDKTypeEnum.STORAGE_REDIS, sdkConfig.getUniqueKey());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public void init() {
.healthCheckResourceSubType("redis")
.simpleClassName("RedisCheck")
.clusterId(1L)
.connectUrl("redis://127.0.0.1:6379")
.connectUrl("127.0.0.1:6379")
.password("")
.build();
redisCheck = new RedisCheck(config);
} catch (RedisException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public SimpleEntry<String, StatefulRedisConnection<String, String>> createClient
RedisURI redisURI = RedisURI.builder()
.withHost(clientHost)
.withPort(clientPort)
.withPassword(redisConfig.getPassword())
.withPassword(redisConfig.getPassword() == null ? "" : redisConfig.getPassword())
.withTimeout(Duration.ofSeconds(redisConfig.getTimeOut()))
.build();
RedisClient redisClient = RedisClient.create(redisURI);
Expand Down

0 comments on commit 32e4170

Please sign in to comment.