Skip to content

Commit

Permalink
Merge pull request #47 from redis-developer/feature/tsdel
Browse files Browse the repository at this point in the history
adding tsdel
  • Loading branch information
jruaux authored Jul 21, 2023
2 parents 66d7dc5 + 9c48210 commit 33515b4
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,11 @@ public RedisFuture<List<V>> tsQueryIndex(V... filters){
return dispatch(timeSeriesCommandBuilder.queryIndex(filters));
}

@Override
public RedisFuture<Long> tsDel(K key, TimeRange timeRange){
return dispatch(timeSeriesCommandBuilder.tsDel(key, timeRange));
}

@Override
public RedisFuture<String> ftCreate(K index, Field<K>... fields) {
return ftCreate(index, null, fields);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,9 @@ public Flux<Object> tsInfoDebug(K key) {
@Override
public Flux<V> tsQueryIndex(V... filters){return createDissolvingFlux(()->timeSeriesCommandBuilder.queryIndex(filters));}

@Override
public Mono<Long> tsDel(K key, TimeRange timeRange) { return createMono(()->timeSeriesCommandBuilder.tsDel(key, timeRange));}

@Override
public Mono<String> ftCreate(K index, Field<K>... fields) {
return ftCreate(index, null, fields);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,6 @@ public interface RedisTimeSeriesAsyncCommands<K, V> {
RedisFuture<List<Object>> tsInfoDebug(K key);

RedisFuture<List<V>> tsQueryIndex(V... filters);

RedisFuture<Long> tsDel(K key, TimeRange range);
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,6 @@ public interface RedisTimeSeriesReactiveCommands<K, V> {
Flux<Object> tsInfoDebug(K key);

Flux<V> tsQueryIndex(V... filters);

Mono<Long> tsDel(K key, TimeRange range);
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,6 @@ public interface RedisTimeSeriesCommands<K, V> {
List<Object> tsInfoDebug(K key);

List<V> tsQueryIndex(V... filter);

Long tsDel(K key, TimeRange range);
}
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,9 @@ public RedisFuture<List<Object>> tsInfoDebug(K key) {
@Override
public RedisFuture<List<V>> tsQueryIndex(V... filters){return delegate.tsQueryIndex(filters);}

@Override
public RedisFuture<Long> tsDel(K key, TimeRange timeRange){return delegate.tsDel(key, timeRange);}

@Override
public RedisFuture<Long> jsonDel(K key) {
return delegate.jsonDel(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,8 @@ public Flux<Object> tsInfoDebug(K key) {
@Override
public Flux<V> tsQueryIndex(V... filters){ return delegate.tsQueryIndex(filters);}

@Override
public Mono<Long> tsDel(K key, TimeRange timeRange) { return delegate.tsDel(key, timeRange);}
@Override
public Mono<Long> jsonDel(K key) {
return delegate.jsonDel(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
public enum TimeSeriesCommandType implements ProtocolKeyword {

ADD, ALTER, CREATE, CREATERULE, DELETERULE, MADD, INCRBY, DECRBY, RANGE, REVRANGE, MRANGE, MREVRANGE, GET, MGET, INFO, QUERYINDEX;
ADD, ALTER, CREATE, CREATERULE, DELETERULE, MADD, INCRBY, DECRBY, RANGE, REVRANGE, MRANGE, MREVRANGE, GET, MGET, INFO, QUERYINDEX, DEL;

private static final String PREFIX = "TS.";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,13 @@ public Command<K, V, List<V>> queryIndex(V... filters){
}
return createCommand(TimeSeriesCommandType.QUERYINDEX, new ValueListOutput<>(codec), args);
}

public Command<K, V, Long> tsDel(K key, TimeRange timeRange){
notNullKey(key);
notNull(timeRange, "time range");
CommandArgs<K, V> args = args(key);
timeRange.build(args);

return createCommand(TimeSeriesCommandType.DEL, new IntegerOutput<>(codec), args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,24 @@ void tsQueryIndex(){
assertTrue(res.contains(key2));
}

@Test
void tsDel(){
String key = "tsDel:key";
connection.sync().del(key);
assertEquals("OK", connection.sync().tsCreate(key, CreateOptions.<String, String>builder().build()));
for(int i = 0; i < 5; i ++){
connection.sync().tsAdd(key, Sample.of(42));

try {
Thread.sleep(20);
} catch (InterruptedException e) {
// ignored
}
}

assertEquals(5, connection.sync().tsDel(key, TimeRange.from(0).to(Long.MAX_VALUE).build()));
}

@Test
void tsMrange() {
RedisTimeSeriesCommands<String, String> ts = connection.sync();
Expand Down

0 comments on commit 33515b4

Please sign in to comment.