diff --git a/src/main/java/org/redisson/RedissonMapCache.java b/src/main/java/org/redisson/RedissonMapCache.java index 44ab4c5f9..19e1e674d 100644 --- a/src/main/java/org/redisson/RedissonMapCache.java +++ b/src/main/java/org/redisson/RedissonMapCache.java @@ -194,6 +194,13 @@ public class RedissonMapCache extends RedissonMap implements RMapCac @Override public Future putIfAbsentAsync(K key, V value, long ttl, TimeUnit unit) { + if (ttl < 0) { + throw new IllegalArgumentException("TTL can't be negative"); + } + if (ttl == 0) { + return putIfAbsentAsync(key, value); + } + if (unit == null) { throw new NullPointerException("TimeUnit param can't be null"); } @@ -274,6 +281,13 @@ public class RedissonMapCache extends RedissonMap implements RMapCac @Override public Future putAsync(K key, V value, long ttl, TimeUnit unit) { + if (ttl < 0) { + throw new IllegalArgumentException("TTL can't be negative"); + } + if (ttl == 0) { + return putAsync(key, value); + } + if (unit == null) { throw new NullPointerException("TimeUnit param can't be null"); } diff --git a/src/main/java/org/redisson/RedissonSetCache.java b/src/main/java/org/redisson/RedissonSetCache.java index bdfaefc98..1df21dfcf 100644 --- a/src/main/java/org/redisson/RedissonSetCache.java +++ b/src/main/java/org/redisson/RedissonSetCache.java @@ -330,6 +330,13 @@ public class RedissonSetCache extends RedissonExpirable implements RSetCache< @Override public Future addAsync(V value, long ttl, TimeUnit unit) { + if (ttl < 0) { + throw new IllegalArgumentException("TTL can't be negative"); + } + if (ttl == 0) { + return addAsync(value); + } + if (unit == null) { throw new NullPointerException("TimeUnit param can't be null"); } diff --git a/src/main/java/org/redisson/core/RMapCache.java b/src/main/java/org/redisson/core/RMapCache.java index 176c6765d..659cb14a2 100644 --- a/src/main/java/org/redisson/core/RMapCache.java +++ b/src/main/java/org/redisson/core/RMapCache.java @@ -38,8 +38,37 @@ import java.util.concurrent.TimeUnit; */ public interface RMapCache extends RMap, RMapCacheAsync { + /** + * If the specified key is not already associated + * with a value, associate it with the given value. + *

+ * Stores value mapped by key with specified time to live. + * Entry expires after specified time to live. + * If the map previously contained a mapping for + * the key, the old value is replaced by the specified value. + * + * @param key + * @param value + * @param ttl - time to live for key\value entry. + * If 0 then stores infinitely. + * @param unit + * @return previous associated value + */ V putIfAbsent(K key, V value, long ttl, TimeUnit unit); + /** + * Stores value mapped by key with specified time to live. + * Entry expires after specified time to live. + * If the map previously contained a mapping for + * the key, the old value is replaced by the specified value. + * + * @param key + * @param value + * @param ttl - time to live for key\value entry. + * If 0 then stores infinitely. + * @param unit + * @return previous associated value + */ V put(K key, V value, long ttl, TimeUnit unit); /** diff --git a/src/main/java/org/redisson/core/RMapCacheAsync.java b/src/main/java/org/redisson/core/RMapCacheAsync.java index fae0bf58f..108e2ddb0 100644 --- a/src/main/java/org/redisson/core/RMapCacheAsync.java +++ b/src/main/java/org/redisson/core/RMapCacheAsync.java @@ -40,8 +40,37 @@ import io.netty.util.concurrent.Future; */ public interface RMapCacheAsync extends RMapAsync { + /** + * If the specified key is not already associated + * with a value, associate it with the given value. + *

+ * Stores value mapped by key with specified time to live. + * Entry expires after specified time to live. + * If the map previously contained a mapping for + * the key, the old value is replaced by the specified value. + * + * @param key + * @param value + * @param ttl - time to live for key\value entry. + * If 0 then stores infinitely. + * @param unit + * @return previous associated value + */ Future putIfAbsentAsync(K key, V value, long ttl, TimeUnit unit); + /** + * Stores value mapped by key with specified time to live. + * Entry expires after specified time to live. + * If the map previously contained a mapping for + * the key, the old value is replaced by the specified value. + * + * @param key + * @param value + * @param ttl - time to live for key\value entry. + * If 0 then stores infinitely. + * @param unit + * @return previous associated value + */ Future putAsync(K key, V value, long ttl, TimeUnit unit); /** diff --git a/src/main/java/org/redisson/core/RSetCache.java b/src/main/java/org/redisson/core/RSetCache.java index 22965b5d8..6707b9b52 100644 --- a/src/main/java/org/redisson/core/RSetCache.java +++ b/src/main/java/org/redisson/core/RSetCache.java @@ -41,6 +41,18 @@ import java.util.concurrent.TimeUnit; */ public interface RSetCache extends Set, RExpirable, RSetCacheAsync { + /** + * Stores value with specified time to live. + * Value expires after specified time to live. + * + * @param key + * @param value + * @param ttl - time to live for key\value entry. + * If 0 then stores infinitely. + * @param unit + * @return true if value has been added. false + * if value already been in collection. + */ boolean add(V value, long ttl, TimeUnit unit); /** diff --git a/src/main/java/org/redisson/core/RSetCacheAsync.java b/src/main/java/org/redisson/core/RSetCacheAsync.java index 1b45f31b6..b4f6b2eba 100644 --- a/src/main/java/org/redisson/core/RSetCacheAsync.java +++ b/src/main/java/org/redisson/core/RSetCacheAsync.java @@ -28,6 +28,18 @@ import io.netty.util.concurrent.Future; */ public interface RSetCacheAsync extends RCollectionAsync { + /** + * Stores value with specified time to live. + * Value expires after specified time to live. + * + * @param key + * @param value + * @param ttl - time to live for key\value entry. + * If 0 then stores infinitely. + * @param unit + * @return true if value has been added. false + * if value already been in collection. + */ Future addAsync(V value, long ttl, TimeUnit unit); /**