RTimeSeries.remove method added

pull/2791/head
Nikita Koksharov 5 years ago
parent 775a93b4ed
commit d8391d1a57

@ -159,6 +159,30 @@ public class RedissonTimeSeries<V> extends RedissonExpirable implements RTimeSer
System.currentTimeMillis(), timestamp);
}
@Override
public boolean remove(long timestamp) {
return get(removeAsync(timestamp));
}
@Override
public RFuture<Boolean> removeAsync(long timestamp) {
return commandExecutor.evalWriteAsync(getName(), codec, RedisCommands.EVAL_BOOLEAN,
"local values = redis.call('zrangebyscore', KEYS[1], ARGV[2], ARGV[2]);" +
"if #values == 0 then " +
"return 0;" +
"end;" +
"local expirationDate = redis.call('zscore', KEYS[2], values[1]); " +
"if expirationDate ~= false and tonumber(expirationDate) <= tonumber(ARGV[1]) then " +
"return 0;" +
"end;" +
"redis.call('zrem', KEYS[2], values[1]); " +
"redis.call('zrem', KEYS[1], values[1]); " +
"return 1;",
Arrays.asList(getName(), getTimeoutSetName()),
System.currentTimeMillis(), timestamp);
}
@Override
public V last() {
return get(lastAsync());

@ -82,6 +82,14 @@ public interface RTimeSeries<V> extends RExpirable, Iterable<V>, RTimeSeriesAsyn
*/
V get(long timestamp);
/**
* Removes object by specified <code>timestamp</code>.
*
* @param timestamp - object timestamp
* @return <code>true</code> if an element was removed as a result of this call
*/
boolean remove(long timestamp);
/**
* Removes and returns the head elements or {@code null} if this time-series collection is empty.
*

@ -84,6 +84,14 @@ public interface RTimeSeriesAsync<V> extends RExpirableAsync {
*/
RFuture<V> getAsync(long timestamp);
/**
* Removes object by specified <code>timestamp</code>.
*
* @param timestamp - object timestamp
* @return <code>true</code> if an element was removed as a result of this call
*/
RFuture<Boolean> removeAsync(long timestamp);
/**
* Removes and returns the head elements or {@code null} if this time-series collection is empty.
*

@ -94,6 +94,14 @@ public interface RTimeSeriesReactive<V> extends RExpirableReactive {
*/
Mono<V> get(long timestamp);
/**
* Removes object by specified <code>timestamp</code>.
*
* @param timestamp - object timestamp
* @return <code>true</code> if an element was removed as a result of this call
*/
Mono<Boolean> remove(long timestamp);
/**
* Removes and returns the head elements or {@code null} if this time-series collection is empty.
*

@ -96,6 +96,14 @@ public interface RTimeSeriesRx<V> extends RExpirableRx {
*/
Maybe<V> get(long timestamp);
/**
* Removes object by specified <code>timestamp</code>.
*
* @param timestamp - object timestamp
* @return <code>true</code> if an element was removed as a result of this call
*/
Single<Boolean> remove(long timestamp);
/**
* Removes and returns the head elements or {@code null} if this time-series collection is empty.
*

@ -64,6 +64,10 @@ public class RedissonTimeSeriesTest extends BaseTest {
assertThat(t.size()).isEqualTo(2);
assertThat(t.range(1, 4)).containsExactly("10", "40");
assertThat(t.rangeReversed(1, 4)).containsExactly("40", "10");
assertThat(t.remove(4)).isTrue();
assertThat(t.remove(5)).isFalse();
assertThat(t.size()).isEqualTo(1);
}
@Test

Loading…
Cancel
Save