Skip to content

Commit bea7704

Browse files
committed
Polish 'Add spring.data.redis.lettuce.read-from property'
1 parent b42429c commit bea7704

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/redis/LettuceConnectionConfiguration.java

+12-4
Original file line numberDiff line numberDiff line change
@@ -174,17 +174,25 @@ private void applyProperties(LettuceClientConfiguration.LettuceClientConfigurati
174174
}
175175
}
176176

177-
private static ReadFrom getReadFrom(String readFrom) {
177+
private ReadFrom getReadFrom(String readFrom) {
178178
int index = readFrom.indexOf(':');
179179
if (index == -1) {
180-
String name = readFrom.replaceAll("-", "");
181-
return ReadFrom.valueOf(name);
180+
return ReadFrom.valueOf(getCanonicalReadFromName(readFrom));
182181
}
183-
String name = readFrom.substring(0, index).replaceAll("-", "");
182+
String name = getCanonicalReadFromName(readFrom.substring(0, index));
184183
String value = readFrom.substring(index + 1);
185184
return ReadFrom.valueOf(name + ":" + value);
186185
}
187186

187+
private String getCanonicalReadFromName(String name) {
188+
StringBuilder canonicalName = new StringBuilder(name.length());
189+
name.chars()
190+
.filter(Character::isLetterOrDigit)
191+
.map(Character::toLowerCase)
192+
.forEach((c) -> canonicalName.append((char) c));
193+
return canonicalName.toString();
194+
}
195+
188196
private ClientOptions createClientOptions(
189197
ObjectProvider<LettuceClientOptionsBuilderCustomizer> clientConfigurationBuilderCustomizers) {
190198
ClientOptions.Builder builder = initializeClientOptionsBuilder();

0 commit comments

Comments
 (0)