From 5793388f10661aa34baec83b88077e987cf07593 Mon Sep 17 00:00:00 2001 From: Nikita Koksharov Date: Wed, 3 Feb 2021 15:18:04 +0300 Subject: [PATCH] Feature - add expireAt(Instant) method to RExpirable objects. #3399 --- .../java/org/redisson/RedissonExpirable.java | 13 ++++++++++++- .../main/java/org/redisson/api/RExpirable.java | 18 ++++++++++++++---- .../java/org/redisson/api/RExpirableAsync.java | 18 ++++++++++++++---- .../org/redisson/api/RExpirableReactive.java | 18 ++++++++++++++---- .../java/org/redisson/api/RExpirableRx.java | 18 ++++++++++++++---- 5 files changed, 68 insertions(+), 17 deletions(-) diff --git a/redisson/src/main/java/org/redisson/RedissonExpirable.java b/redisson/src/main/java/org/redisson/RedissonExpirable.java index a00c296b7..bafcca539 100644 --- a/redisson/src/main/java/org/redisson/RedissonExpirable.java +++ b/redisson/src/main/java/org/redisson/RedissonExpirable.java @@ -15,6 +15,7 @@ */ package org.redisson; +import java.time.Instant; import java.util.Arrays; import java.util.Date; import java.util.concurrent.TimeUnit; @@ -59,7 +60,17 @@ abstract class RedissonExpirable extends RedissonObject implements RExpirable { @Override public RFuture expireAtAsync(long timestamp) { - return commandExecutor.writeAsync(getName(), StringCodec.INSTANCE, RedisCommands.PEXPIREAT, getName(), timestamp); + return expireAtAsync(Instant.ofEpochMilli(timestamp)); + } + + @Override + public boolean expireAt(Instant instant) { + return get(expireAtAsync(instant)); + } + + @Override + public RFuture expireAtAsync(Instant instant) { + return commandExecutor.writeAsync(getName(), StringCodec.INSTANCE, RedisCommands.PEXPIREAT, getName(), instant.toEpochMilli()); } @Override diff --git a/redisson/src/main/java/org/redisson/api/RExpirable.java b/redisson/src/main/java/org/redisson/api/RExpirable.java index ae6ebe65d..e6f871026 100644 --- a/redisson/src/main/java/org/redisson/api/RExpirable.java +++ b/redisson/src/main/java/org/redisson/api/RExpirable.java @@ -15,6 +15,7 @@ */ package org.redisson.api; +import java.time.Instant; import java.util.Date; import java.util.concurrent.TimeUnit; @@ -38,23 +39,32 @@ public interface RExpirable extends RObject, RExpirableAsync { boolean expire(long timeToLive, TimeUnit timeUnit); /** - * Set an expire date for object. When expire date comes - * the key will automatically be deleted. + * Use {@link #expireAt(Instant)} instead * * @param timestamp - expire date in milliseconds (Unix timestamp) * @return true if the timeout was set and false if not */ + @Deprecated boolean expireAt(long timestamp); /** - * Set an expire date for object. When expire date comes - * the key will automatically be deleted. + * Use {@link #expireAt(Instant)} instead * * @param timestamp - expire date * @return true if the timeout was set and false if not */ + @Deprecated boolean expireAt(Date timestamp); + /** + * Set an expire date for object. When expire date comes + * the key will automatically be deleted. + * + * @param instant - expire date + * @return true if the timeout was set and false if not + */ + boolean expireAt(Instant instant); + /** * Clear an expire timeout or expire date for object. * diff --git a/redisson/src/main/java/org/redisson/api/RExpirableAsync.java b/redisson/src/main/java/org/redisson/api/RExpirableAsync.java index 554a7732e..528ef9c31 100644 --- a/redisson/src/main/java/org/redisson/api/RExpirableAsync.java +++ b/redisson/src/main/java/org/redisson/api/RExpirableAsync.java @@ -15,6 +15,7 @@ */ package org.redisson.api; +import java.time.Instant; import java.util.Date; import java.util.concurrent.TimeUnit; @@ -38,23 +39,32 @@ public interface RExpirableAsync extends RObjectAsync { RFuture expireAsync(long timeToLive, TimeUnit timeUnit); /** - * Set an expire date for object in async mode. When expire date comes - * the key will automatically be deleted. + * Use {@link #expireAtAsync(Instant)} instead * * @param timestamp - expire date * @return true if the timeout was set and false if not */ + @Deprecated RFuture expireAtAsync(Date timestamp); /** - * Set an expire date for object in async mode. When expire date comes - * the key will automatically be deleted. + * Use {@link #expireAtAsync(Instant)} instead * * @param timestamp - expire date in milliseconds (Unix timestamp) * @return true if the timeout was set and false if not */ + @Deprecated RFuture expireAtAsync(long timestamp); + /** + * Set an expire date for object. When expire date comes + * the key will automatically be deleted. + * + * @param instant - expire date + * @return true if the timeout was set and false if not + */ + RFuture expireAtAsync(Instant instant); + /** * Clear an expire timeout or expire date for object in async mode. * Object will not be deleted. diff --git a/redisson/src/main/java/org/redisson/api/RExpirableReactive.java b/redisson/src/main/java/org/redisson/api/RExpirableReactive.java index 736339fa6..bbd198cf3 100644 --- a/redisson/src/main/java/org/redisson/api/RExpirableReactive.java +++ b/redisson/src/main/java/org/redisson/api/RExpirableReactive.java @@ -15,6 +15,7 @@ */ package org.redisson.api; +import java.time.Instant; import java.util.Date; import java.util.concurrent.TimeUnit; @@ -40,23 +41,32 @@ public interface RExpirableReactive extends RObjectReactive { Mono expire(long timeToLive, TimeUnit timeUnit); /** - * Set an expire date for object in mode. When expire date comes - * the key will automatically be deleted. + * Use {@link #expireAt(Instant)} instead * * @param timestamp - expire date * @return true if the timeout was set and false if not */ + @Deprecated Mono expireAt(Date timestamp); /** - * Set an expire date for object in mode. When expire date comes - * the key will automatically be deleted. + * Use {@link #expireAt(Instant)} instead * * @param timestamp - expire date in milliseconds (Unix timestamp) * @return true if the timeout was set and false if not */ + @Deprecated Mono expireAt(long timestamp); + /** + * Set an expire date for object. When expire date comes + * the key will automatically be deleted. + * + * @param instant - expire date + * @return true if the timeout was set and false if not + */ + Mono expireAt(Instant instant); + /** * Clear an expire timeout or expire date for object in mode. * Object will not be deleted. diff --git a/redisson/src/main/java/org/redisson/api/RExpirableRx.java b/redisson/src/main/java/org/redisson/api/RExpirableRx.java index 6e848a823..d88c7f3cd 100644 --- a/redisson/src/main/java/org/redisson/api/RExpirableRx.java +++ b/redisson/src/main/java/org/redisson/api/RExpirableRx.java @@ -15,6 +15,7 @@ */ package org.redisson.api; +import java.time.Instant; import java.util.Date; import java.util.concurrent.TimeUnit; @@ -40,23 +41,32 @@ public interface RExpirableRx extends RObjectRx { Single expire(long timeToLive, TimeUnit timeUnit); /** - * Set an expire date for object in mode. When expire date comes - * the key will automatically be deleted. + * Use {@link #expireAt(Instant)} instead * * @param timestamp - expire date * @return true if the timeout was set and false if not */ + @Deprecated Single expireAt(Date timestamp); /** - * Set an expire date for object in mode. When expire date comes - * the key will automatically be deleted. + * Use {@link #expireAt(Instant)} instead * * @param timestamp - expire date in milliseconds (Unix timestamp) * @return true if the timeout was set and false if not */ + @Deprecated Single expireAt(long timestamp); + /** + * Set an expire date for object. When expire date comes + * the key will automatically be deleted. + * + * @param instant - expire date + * @return true if the timeout was set and false if not + */ + Single expireAt(Instant instant); + /** * Clear an expire timeout or expire date for object in mode. * Object will not be deleted.