diff --git a/src/main/java/org/springframework/data/redis/cache/DefaultRedisCacheWriter.java b/src/main/java/org/springframework/data/redis/cache/DefaultRedisCacheWriter.java index 600cb4f0b7..1ea148597d 100644 --- a/src/main/java/org/springframework/data/redis/cache/DefaultRedisCacheWriter.java +++ b/src/main/java/org/springframework/data/redis/cache/DefaultRedisCacheWriter.java @@ -65,6 +65,7 @@ * @author André Prata * @author John Blum * @author ChanYoung Joung + * @author Youngsuk Kim * @since 2.0 */ class DefaultRedisCacheWriter implements RedisCacheWriter { @@ -212,7 +213,7 @@ public void enable(Consumer configurationConsumer) { public CacheLockingConfiguration sleepTime(Duration sleepTime) { Assert.notNull(sleepTime, "Lock sleep time must not be null"); - Assert.isTrue(!sleepTime.isZero() && !sleepTime.isNegative(), + Assert.isTrue(isPositiveDuration(sleepTime), "Lock sleep time must not be null zero or negative"); this.lockSleepTime = sleepTime; @@ -563,7 +564,7 @@ private T executeLockFree(Function callback) { * @return {@literal true} if {@link RedisCacheWriter} uses locks. */ private boolean isLockingCacheWriter() { - return !this.sleepTime.isZero() && !this.sleepTime.isNegative(); + return isPositiveDuration(this.sleepTime); } private void checkAndPotentiallyWaitUntilUnlocked(String name, RedisConnection connection) { @@ -601,6 +602,10 @@ private static boolean shouldExpireWithin(@Nullable Duration ttl) { return ttl != null && !ttl.isZero() && !ttl.isNegative(); } + private static boolean isPositiveDuration(Duration duration) { + return !duration.isZero() && !duration.isNegative(); + } + /** * Interface for asynchronous cache retrieval. *