diff --git a/src/main/java/org/springframework/data/redis/core/BoundKeyOperations.java b/src/main/java/org/springframework/data/redis/core/BoundKeyOperations.java index bf0cb1a99..10fffb03c 100644 --- a/src/main/java/org/springframework/data/redis/core/BoundKeyOperations.java +++ b/src/main/java/org/springframework/data/redis/core/BoundKeyOperations.java @@ -64,14 +64,15 @@ public interface BoundKeyOperations { * Sets the key time-to-live/expiration. * * @param timeout must not be {@literal null}. - * @return true if expiration was set, false otherwise. {@literal null} when used in pipeline / transaction. + * @return {@literal true} if expiration was set, {@literal false} otherwise. {@literal null} when used in pipeline / + * transaction. + * @throws IllegalArgumentException if the timeout is {@literal null}. * @since 2.3 */ @Nullable default Boolean expire(Duration timeout) { Assert.notNull(timeout, "Timeout must not be null"); - Assert.isTrue(!timeout.isNegative(), "Timeout must not be negative"); return expire(timeout.toMillis(), TimeUnit.MILLISECONDS); } @@ -98,14 +99,16 @@ public interface BoundKeyOperations { /** * Sets the key time-to-live/expiration. * - * @param time expiration time. - * @return true if expiration was set, false otherwise. {@literal null} when used in pipeline / transaction. + * @param expireAt expiration time. + * @return {@literal true} if expiration was set, {@literal false} otherwise. {@literal null} when used in pipeline / + * transaction. + * @throws IllegalArgumentException if the instant is {@literal null} or too large to represent as a {@code Date}. * @since 2.3 */ @Nullable default Boolean expireAt(Instant expireAt) { - Assert.notNull(expireAt, "Timestamp must not be null"); + Assert.notNull(expireAt, "ExpireAt must not be null"); return expireAt(Date.from(expireAt)); } diff --git a/src/main/java/org/springframework/data/redis/core/BoundListOperations.java b/src/main/java/org/springframework/data/redis/core/BoundListOperations.java index 1ec131dbb..fee5e34e7 100644 --- a/src/main/java/org/springframework/data/redis/core/BoundListOperations.java +++ b/src/main/java/org/springframework/data/redis/core/BoundListOperations.java @@ -196,6 +196,7 @@ public interface BoundListOperations extends BoundKeyOperations { * * @param timeout must not be {@literal null}. * @return {@literal null} when timeout reached or used in pipeline / transaction. + * @throws IllegalArgumentException if the timeout is {@literal null} or negative. * @since 2.3 * @see Redis Documentation: BLPOP */ @@ -235,6 +236,7 @@ public interface BoundListOperations extends BoundKeyOperations { * * @param timeout must not be {@literal null}. * @return {@literal null} when timeout reached or used in pipeline / transaction. + * @throws IllegalArgumentException if the timeout is {@literal null} or negative. * @since 2.3 * @see Redis Documentation: BRPOP */ diff --git a/src/main/java/org/springframework/data/redis/core/ListOperations.java b/src/main/java/org/springframework/data/redis/core/ListOperations.java index 4e0a7b166..015e87c32 100644 --- a/src/main/java/org/springframework/data/redis/core/ListOperations.java +++ b/src/main/java/org/springframework/data/redis/core/ListOperations.java @@ -243,6 +243,7 @@ public interface ListOperations { * @param key must not be {@literal null}. * @param timeout must not be {@literal null}. * @return can be {@literal null}. + * @throws IllegalArgumentException if the timeout is {@literal null} or negative. * @since 2.3 * @see Redis Documentation: BLPOP */ @@ -330,6 +331,7 @@ public interface ListOperations { * @param destinationKey must not be {@literal null}. * @param timeout must not be {@literal null}. * @return can be {@literal null}. + * @throws IllegalArgumentException if the timeout is {@literal null} or negative. * @since 2.3 * @see Redis Documentation: BRPOPLPUSH */ diff --git a/src/main/java/org/springframework/data/redis/core/RedisOperations.java b/src/main/java/org/springframework/data/redis/core/RedisOperations.java index af2d3256b..a7bff5392 100644 --- a/src/main/java/org/springframework/data/redis/core/RedisOperations.java +++ b/src/main/java/org/springframework/data/redis/core/RedisOperations.java @@ -289,13 +289,13 @@ public interface RedisOperations { * @param key must not be {@literal null}. * @param timeout must not be {@literal null}. * @return {@literal null} when used in pipeline / transaction. + * @throws IllegalArgumentException if the timeout is {@literal null}. * @since 2.3 */ @Nullable default Boolean expire(K key, Duration timeout) { Assert.notNull(timeout, "Timeout must not be null"); - Assert.isTrue(!timeout.isNegative(), "Timeout must not be negative"); return TimeoutUtils.hasMillis(timeout) ? expire(key, timeout.toMillis(), TimeUnit.MILLISECONDS) : expire(key, timeout.getSeconds(), TimeUnit.SECONDS); @@ -317,6 +317,7 @@ public interface RedisOperations { * @param key must not be {@literal null}. * @param expireAt must not be {@literal null}. * @return {@literal null} when used in pipeline / transaction. + * @throws IllegalArgumentException if the instant is {@literal null} or too large to represent as a {@code Date}. * @since 2.3 */ @Nullable diff --git a/src/test/java/org/springframework/data/redis/core/DefaultListOperationsTests.java b/src/test/java/org/springframework/data/redis/core/DefaultListOperationsTests.java index 68e75a2b9..79c18034d 100644 --- a/src/test/java/org/springframework/data/redis/core/DefaultListOperationsTests.java +++ b/src/test/java/org/springframework/data/redis/core/DefaultListOperationsTests.java @@ -131,8 +131,9 @@ public class DefaultListOperationsTests { assertThat(listOps.range(key, 0, -1)).contains(v3, v2, v1); } - @Test + @Test // DATAREDIS-611 public void testLeftPopDuration() { + // 1 ms timeout gets upgraded to 1 sec timeout at the moment assumeTrue(RedisTestProfileValueSource.matches("runLongTests", "true")); assumeTrue(valueFactory instanceof StringObjectFactory); @@ -146,8 +147,9 @@ public class DefaultListOperationsTests { assertThat(listOps.leftPop(key, Duration.ofSeconds(1))).isEqualTo(v1); } - @Test + @Test // DATAREDIS-611 public void testRightPopDuration() { + // 1 ms timeout gets upgraded to 1 sec timeout at the moment assumeTrue(RedisTestProfileValueSource.matches("runLongTests", "true")); assumeTrue(valueFactory instanceof StringObjectFactory);