Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace deprecated methods with builder pattern for RedisURI construction #1772

Merged
merged 5 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ public Boolean checkType(String responseStr) {
@Override
public void parse(String resp, List<String> aliasFields, HttpProtocol http, CollectRep.MetricsData.Builder builder) {
CollectRep.ValueRow.Builder valueRowBuilder = CollectRep.ValueRow.newBuilder();
for (String aliasField : aliasFields) {
valueRowBuilder.addColumns(CommonConstants.NULL_VALUE);
}
aliasFields.forEach(aliasField -> valueRowBuilder.addColumns(CommonConstants.NULL_VALUE));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -268,16 +268,16 @@ private RedisClient buildSingleClient(RedisProtocol redisProtocol) {
}

private RedisURI redisUri(RedisProtocol redisProtocol) {
RedisURI redisUri = RedisURI.create(redisProtocol.getHost(), Integer.parseInt(redisProtocol.getPort()));
RedisURI.Builder redisUriBuilder = RedisURI.builder().withHost(redisProtocol.getHost()).withPort(Integer.parseInt(redisProtocol.getPort()));
if (StringUtils.hasText(redisProtocol.getUsername())) {
redisUri.setUsername(redisProtocol.getUsername());
redisUriBuilder.withClientName(redisProtocol.getUsername());
}
if (StringUtils.hasText(redisProtocol.getPassword())) {
redisUri.setPassword(redisProtocol.getPassword().toCharArray());
redisUriBuilder.withPassword(redisProtocol.getPassword().toCharArray());
}
Duration timeout = Duration.ofMillis(CollectUtil.getTimeout(redisProtocol.getTimeout()));
redisUri.setTimeout(timeout);
return redisUri;
redisUriBuilder.withTimeout(timeout);
return redisUriBuilder.build();
}

private String removeCr(String value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

import java.util.*;

import org.apache.commons.lang3.StringUtils;

/**
* json path parser
*/
Expand All @@ -45,7 +47,7 @@ public class JsonPathParser {
* @return content [{'name': 'tom', 'speed': '433'},{'name': 'lili', 'speed': '543'}]
*/
public static List<Object> parseContentWithJsonPath(String content, String jsonPath) {
if (content == null || jsonPath == null || "".equals(content) || "".equals(jsonPath)) {
if (StringUtils.isAnyEmpty(content, jsonPath)) {
return Collections.emptyList();
}
return PARSER.parse(content).read(jsonPath);
Expand All @@ -58,7 +60,7 @@ public static List<Object> parseContentWithJsonPath(String content, String jsonP
* @return content [{'name': 'tom', 'speed': '433'},{'name': 'lili', 'speed': '543'}]
*/
public static <T> T parseContentWithJsonPath(String content, String jsonPath, TypeRef<T> typeRef) {
if (content == null || jsonPath == null || "".equals(content) || "".equals(jsonPath)) {
if (StringUtils.isAnyEmpty(content, jsonPath)) {
return null;
}
return PARSER.parse(content).read(jsonPath, typeRef);
Expand Down
Loading