DATAREDIS-782 - Polishing.
Add setIfPresent(…) with expiry to reactive API. Add since tags, minor tweaks to javadoc and tests. Original pull request: #320.
This commit is contained in:
@@ -63,6 +63,7 @@ public interface BoundValueOperations<K, V> extends BoundKeyOperations<K> {
|
||||
* @param timeout
|
||||
* @param unit must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.1
|
||||
* @see <a href="http://redis.io/commands/set">Redis Documentation: SET</a>
|
||||
*/
|
||||
@Nullable
|
||||
|
||||
@@ -28,7 +28,7 @@ class DefaultBoundValueOperations<K, V> extends DefaultBoundKeyOperations<K> imp
|
||||
private final ValueOperations<K, V> ops;
|
||||
|
||||
/**
|
||||
* Constructs a new <code>DefaultBoundValueOperations</code> instance.
|
||||
* Constructs a new {@link DefaultBoundValueOperations} instance.
|
||||
*
|
||||
* @param key
|
||||
* @param operations
|
||||
|
||||
@@ -86,10 +86,10 @@ class DefaultReactiveValueOperations<K, V> implements ReactiveValueOperations<K,
|
||||
connection -> connection.set(rawKey(key), rawValue(value), Expiration.persistent(), SetOption.SET_IF_ABSENT));
|
||||
}
|
||||
|
||||
@Override
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.ReactiveValueOperations#setIfAbsent(java.lang.Object, java.lang.Object, long, java.util.concurrent.TimeUnit)
|
||||
* @see org.springframework.data.redis.core.ReactiveValueOperations#setIfAbsent(java.lang.Object, java.lang.Object, java.time.Duration)
|
||||
*/
|
||||
@Override
|
||||
public Mono<Boolean> setIfAbsent(K key, V value, Duration timeout) {
|
||||
|
||||
Assert.notNull(key, "Key must not be null!");
|
||||
@@ -111,6 +111,19 @@ class DefaultReactiveValueOperations<K, V> implements ReactiveValueOperations<K,
|
||||
connection -> connection.set(rawKey(key), rawValue(value), Expiration.persistent(), SetOption.SET_IF_PRESENT));
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.ReactiveValueOperations#setIfPresent(java.lang.Object, java.lang.Object, java.time.Duration)
|
||||
*/
|
||||
@Override
|
||||
public Mono<Boolean> setIfPresent(K key, V value, Duration timeout) {
|
||||
|
||||
Assert.notNull(key, "Key must not be null!");
|
||||
Assert.notNull(timeout, "Duration must not be null!");
|
||||
|
||||
return createMono(
|
||||
connection -> connection.set(rawKey(key), rawValue(value), Expiration.from(timeout), SetOption.SET_IF_PRESENT));
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.ReactiveValueOperations#multiSet(java.util.Map)
|
||||
*/
|
||||
|
||||
@@ -24,7 +24,7 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.data.redis.connection.RedisConnection;
|
||||
import org.springframework.data.redis.connection.RedisStringCommands;
|
||||
import org.springframework.data.redis.connection.RedisStringCommands.SetOption;
|
||||
import org.springframework.data.redis.core.types.Expiration;
|
||||
|
||||
/**
|
||||
@@ -267,12 +267,12 @@ class DefaultValueOperations<K, V> extends AbstractOperations<K, V> implements V
|
||||
*/
|
||||
@Override
|
||||
public Boolean setIfAbsent(K key, V value, long timeout, TimeUnit unit) {
|
||||
|
||||
byte[] rawKey = rawKey(key);
|
||||
byte[] rawValue = rawValue(value);
|
||||
|
||||
Expiration expiration = Expiration.from(timeout, unit);
|
||||
RedisStringCommands.SetOption setOption = RedisStringCommands.SetOption.ifAbsent();
|
||||
return execute(connection -> connection.set(rawKey, rawValue, expiration, setOption), true);
|
||||
return execute(connection -> connection.set(rawKey, rawValue, expiration, SetOption.ifAbsent()), true);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -65,6 +65,7 @@ public interface ReactiveValueOperations<K, V> {
|
||||
* @param key must not be {@literal null}.
|
||||
* @param value
|
||||
* @param timeout must not be {@literal null}.
|
||||
* @since 2.1
|
||||
* @see <a href="http://redis.io/commands/set">Redis Documentation: SET</a>
|
||||
*/
|
||||
Mono<Boolean> setIfAbsent(K key, V value, Duration timeout);
|
||||
@@ -78,6 +79,17 @@ public interface ReactiveValueOperations<K, V> {
|
||||
*/
|
||||
Mono<Boolean> setIfPresent(K key, V value);
|
||||
|
||||
/**
|
||||
* Set {@code key} to hold the string {@code value} and expiration {@code timeout} if {@code key} is present.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @param value
|
||||
* @param timeout must not be {@literal null}.
|
||||
* @since 2.1
|
||||
* @see <a href="http://redis.io/commands/set">Redis Documentation: SET</a>
|
||||
*/
|
||||
Mono<Boolean> setIfPresent(K key, V value, Duration timeout);
|
||||
|
||||
/**
|
||||
* Set multiple keys to multiple values using key-value pairs provided in {@code tuple}.
|
||||
*
|
||||
|
||||
@@ -68,9 +68,10 @@ public interface ValueOperations<K, V> {
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @param value
|
||||
* @param timeout
|
||||
* @param timeout must not be {@literal null}.
|
||||
* @param unit must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.1
|
||||
* @see <a href="http://redis.io/commands/set">Redis Documentation: SET</a>
|
||||
*/
|
||||
@Nullable
|
||||
|
||||
Reference in New Issue
Block a user