DATAREDIS-784 - Add support for reactive increment and decrement commands to ReactiveValueOperations.
We now support reactive execution of the following increment and decrement commands through ReactiveValueOperations: - INCR - INCRBY - INCRBYFLOAT - DECR - DECRBY Original pull request: #322.
This commit is contained in:
committed by
Mark Paluch
parent
452feb9420
commit
8857f96b9f
@@ -273,6 +273,61 @@ class DefaultReactiveValueOperations<K, V> implements ReactiveValueOperations<K,
|
||||
|
||||
return template.createMono(connection -> connection.keyCommands().del(rawKey(key))).map(l -> l != 0);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.ReactiveValueOperations#increment(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public Mono<Long> increment(K key) {
|
||||
|
||||
Assert.notNull(key, "Key must not be null!");
|
||||
|
||||
return incrementBy(key, 1L);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.ReactiveValueOperations#incrementBy(java.lang.Object, long)
|
||||
*/
|
||||
@Override
|
||||
public Mono<Long> incrementBy(K key, long delta) {
|
||||
|
||||
Assert.notNull(key, "Key must not be null!");
|
||||
|
||||
return template.createMono(connection -> connection.numberCommands().incrBy(rawKey(key), delta));
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.ReactiveValueOperations#incrementBy(java.lang.Object, double)
|
||||
*/
|
||||
@Override
|
||||
public Mono<Double> incrementBy(K key, double delta) {
|
||||
|
||||
Assert.notNull(key, "Key must not be null!");
|
||||
|
||||
return template.createMono(connection -> connection.numberCommands().incrBy(rawKey(key), delta));
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.ReactiveValueOperations#decrement(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public Mono<Long> decrement(K key) {
|
||||
|
||||
Assert.notNull(key, "Key must not be null!");
|
||||
|
||||
return incrementBy(key, -1L);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.ReactiveValueOperations#decrementBy(java.lang.Object, long)
|
||||
*/
|
||||
@Override
|
||||
public Mono<Long> decrementBy(K key, long delta) {
|
||||
|
||||
Assert.notNull(key, "Key must not be null!");
|
||||
|
||||
return incrementBy(key, -delta);
|
||||
}
|
||||
|
||||
private <T> Mono<T> createMono(Function<ReactiveStringCommands, Publisher<T>> function) {
|
||||
|
||||
|
||||
@@ -193,4 +193,44 @@ public interface ReactiveValueOperations<K, V> {
|
||||
* @param key must not be {@literal null}.
|
||||
*/
|
||||
Mono<Boolean> delete(K key);
|
||||
|
||||
/**
|
||||
* Increments the number stored at {@code key} by one.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @see <a href="http://redis.io/commands/incr">Redis Documentation: INCR</a>
|
||||
*/
|
||||
Mono<Long> increment(K key);
|
||||
|
||||
/**
|
||||
* Increments the number stored at {@code key} by {@code delta}.
|
||||
* @param key must not be {@literal null}.
|
||||
* @param delta
|
||||
* @see <a href="http://redis.io/commands/incrby">Redis Documentation: INCRBY</a>
|
||||
*/
|
||||
Mono<Long> incrementBy(K key, long delta);
|
||||
|
||||
/**
|
||||
* Increment the string representing a floating point number stored at {@code key} by {@code delta}.
|
||||
* @param key must not be {@literal null}.
|
||||
* @param delta
|
||||
* @see <a href="http://redis.io/commands/incrbyfloat">Redis Documentation: INCRBYFLOAT</a>
|
||||
*/
|
||||
Mono<Double> incrementBy(K key, double delta);
|
||||
|
||||
/**
|
||||
* Decrements the number stored at {@code key} by one.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @see <a href="http://redis.io/commands/decr">Redis Documentation: DECR</a>
|
||||
*/
|
||||
Mono<Long> decrement(K key);
|
||||
|
||||
/**
|
||||
* Decrements the number stored at {@code key} by {@code delta}.
|
||||
* @param key must not be {@literal null}.
|
||||
* @param delta
|
||||
* @see <a href="http://redis.io/commands/decrby">Redis Documentation: DECRBY</a>
|
||||
*/
|
||||
Mono<Long> decrementBy(K key, long delta);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user