Feature - Add addIfGreater() and addIfLess() methods to RScoredSortedSet object. #3344

pull/3355/head
Nikita Koksharov 4 years ago
parent 0aacc93755
commit 58afd22cb6

@ -263,6 +263,26 @@ public class RedissonScoredSortedSet<V> extends RedissonExpirable implements RSc
return commandExecutor.writeAsync(getName(), codec, RedisCommands.ZADD_BOOL, getName(), "XX", BigDecimal.valueOf(score).toPlainString(), encode(object));
}
@Override
public boolean addIfLess(double score, V object) {
return get(addIfLessAsync(score, object));
}
@Override
public boolean addIfGreater(double score, V object) {
return get(addIfGreaterAsync(score, object));
}
@Override
public RFuture<Boolean> addIfLessAsync(double score, V object) {
return commandExecutor.writeAsync(getName(), codec, RedisCommands.ZADD_BOOL, getName(), "LT", BigDecimal.valueOf(score).toPlainString(), encode(object));
}
@Override
public RFuture<Boolean> addIfGreaterAsync(double score, V object) {
return commandExecutor.writeAsync(getName(), codec, RedisCommands.ZADD_BOOL, getName(), "GT", BigDecimal.valueOf(score).toPlainString(), encode(object));
}
@Override
public V first() {
return get(firstAsync());

@ -336,6 +336,28 @@ public interface RScoredSortedSet<V> extends RScoredSortedSetAsync<V>, Iterable<
*/
boolean addIfExists(double score, V object);
/**
* Adds element to this set only if new score less than current score of existed element.
* <p>
* Requires <b>Redis 6.2.0 and higher.</b>
*
* @param score - object score
* @param object - object itself
* @return <code>true</code> if element added and <code>false</code> if not.
*/
boolean addIfLess(double score, V object);
/**
* Adds element to this set only if new score greater than current score of existed element.
* <p>
* Requires <b>Redis 6.2.0 and higher.</b>
*
* @param score - object score
* @param object - object itself
* @return <code>true</code> if element added and <code>false</code> if not.
*/
boolean addIfGreater(double score, V object);
/**
* Returns size of this set.
*

@ -297,6 +297,28 @@ public interface RScoredSortedSetAsync<V> extends RExpirableAsync, RSortableAsyn
*/
RFuture<Boolean> addIfExistsAsync(double score, V object);
/**
* Adds element to this set only if new score less than current score of existed element.
* <p>
* Requires <b>Redis 6.2.0 and higher.</b>
*
* @param score - object score
* @param object - object itself
* @return <code>true</code> if element added and <code>false</code> if not.
*/
RFuture<Boolean> addIfLessAsync(double score, V object);
/**
* Adds element to this set only if new score greater than current score of existed element.
* <p>
* Requires <b>Redis 6.2.0 and higher.</b>
*
* @param score - object score
* @param object - object itself
* @return <code>true</code> if element added and <code>false</code> if not.
*/
RFuture<Boolean> addIfGreaterAsync(double score, V object);
/**
* Removes a single instance of the specified element from this
* sorted set, if it is present.

@ -320,6 +320,28 @@ public interface RScoredSortedSetReactive<V> extends RExpirableReactive, RSortab
*/
Mono<Boolean> addIfExists(double score, V object);
/**
* Adds element to this set only if new score less than current score of existed element.
* <p>
* Requires <b>Redis 6.2.0 and higher.</b>
*
* @param score - object score
* @param object - object itself
* @return <code>true</code> if element added and <code>false</code> if not.
*/
Mono<Boolean> addIfLess(double score, V object);
/**
* Adds element to this set only if new score greater than current score of existed element.
* <p>
* Requires <b>Redis 6.2.0 and higher.</b>
*
* @param score - object score
* @param object - object itself
* @return <code>true</code> if element added and <code>false</code> if not.
*/
Mono<Boolean> addIfGreater(double score, V object);
/**
* Removes a single instance of the specified element from this
* sorted set, if it is present.

@ -321,6 +321,28 @@ public interface RScoredSortedSetRx<V> extends RExpirableRx, RSortableRx<Set<V>>
*/
Single<Boolean> addIfExists(double score, V object);
/**
* Adds element to this set only if new score less than current score of existed element.
* <p>
* Requires <b>Redis 6.2.0 and higher.</b>
*
* @param score - object score
* @param object - object itself
* @return <code>true</code> if element added and <code>false</code> if not.
*/
Single<Boolean> addIfLess(double score, V object);
/**
* Adds element to this set only if new score greater than current score of existed element.
* <p>
* Requires <b>Redis 6.2.0 and higher.</b>
*
* @param score - object score
* @param object - object itself
* @return <code>true</code> if element added and <code>false</code> if not.
*/
Single<Boolean> addIfGreater(double score, V object);
/**
* Removes a single instance of the specified element from this
* sorted set, if it is present.

Loading…
Cancel
Save