diff --git a/src/main/java/org/springframework/data/redis/cache/BatchStrategies.java b/src/main/java/org/springframework/data/redis/cache/BatchStrategies.java index e8b6f031cc..8d21b9b645 100644 --- a/src/main/java/org/springframework/data/redis/cache/BatchStrategies.java +++ b/src/main/java/org/springframework/data/redis/cache/BatchStrategies.java @@ -16,11 +16,10 @@ package org.springframework.data.redis.cache; import java.util.ArrayList; -import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.NoSuchElementException; -import java.util.Optional; +import java.util.Set; import org.springframework.data.redis.connection.RedisConnection; import org.springframework.data.redis.connection.RedisKeyCommands; @@ -34,6 +33,7 @@ * @author Mark Paluch * @author Christoph Strobl * @author John Blum + * @author Yong-Hyun Kim * @since 2.6 */ public abstract class BatchStrategies { @@ -82,14 +82,15 @@ public long cleanCache(RedisConnection connection, String name, byte[] pattern) RedisKeyCommands commands = connection.keyCommands(); - byte[][] keys = Optional.ofNullable(commands.keys(pattern)).orElse(Collections.emptySet()) - .toArray(new byte[0][]); + Set keys = commands.keys(pattern); - if (keys.length > 0) { - commands.del(keys); - } + if (keys == null || keys.isEmpty()) { + return 0; + } + + commands.del(keys.toArray(new byte[0][])); - return keys.length; + return keys.size(); } } diff --git a/src/main/java/org/springframework/data/redis/connection/RedisPassword.java b/src/main/java/org/springframework/data/redis/connection/RedisPassword.java index d10a5950c3..f996f4de3e 100644 --- a/src/main/java/org/springframework/data/redis/connection/RedisPassword.java +++ b/src/main/java/org/springframework/data/redis/connection/RedisPassword.java @@ -35,6 +35,7 @@ * * @author Mark Paluch * @author Christoph Strobl + * @author Yong-Hyun Kim * @since 2.0 */ public class RedisPassword { @@ -55,10 +56,11 @@ private RedisPassword(char[] thePassword) { */ public static RedisPassword of(@Nullable String passwordAsString) { - return Optional.ofNullable(passwordAsString) // - .filter(StringUtils::hasText) // - .map(it -> new RedisPassword(it.toCharArray())) // - .orElseGet(RedisPassword::none); + if (!StringUtils.hasText(passwordAsString)) { + return none(); + } + + return new RedisPassword(passwordAsString.toCharArray()); } /** @@ -69,10 +71,11 @@ public static RedisPassword of(@Nullable String passwordAsString) { */ public static RedisPassword of(char @Nullable[] passwordAsChars) { - return Optional.ofNullable(passwordAsChars) // - .filter(it -> !ObjectUtils.isEmpty(passwordAsChars)) // - .map(it -> new RedisPassword(Arrays.copyOf(it, it.length))) // - .orElseGet(RedisPassword::none); + if (ObjectUtils.isEmpty(passwordAsChars)) { + return none(); + } + + return new RedisPassword(Arrays.copyOf(passwordAsChars, passwordAsChars.length)); } /**