From 07bb3a57a6fab80534ae0d10b6cfbb8fa7eddce6 Mon Sep 17 00:00:00 2001 From: bread Date: Wed, 3 Dec 2025 22:32:30 +0900 Subject: [PATCH 1/2] Extract duplicate duration validation logic to helper method - Add isPositiveDuration(Duration) helper method - Replace duplicate validation logic at lines 215 and 566 - Improve code maintainability and readability Signed-off-by: bread --- .../data/redis/cache/DefaultRedisCacheWriter.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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..4f9f9749b6 100644 --- a/src/main/java/org/springframework/data/redis/cache/DefaultRedisCacheWriter.java +++ b/src/main/java/org/springframework/data/redis/cache/DefaultRedisCacheWriter.java @@ -212,7 +212,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 +563,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 +601,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. * From fb1278e933e4987dab0f637e34d5c4ce8c9cb865 Mon Sep 17 00:00:00 2001 From: bread Date: Wed, 3 Dec 2025 22:36:01 +0900 Subject: [PATCH 2/2] Add author to class header Signed-off-by: bread --- .../data/redis/cache/DefaultRedisCacheWriter.java | 1 + 1 file changed, 1 insertion(+) 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 4f9f9749b6..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 {