Skip to content

Commit

Permalink
adding ts.queryindex
Browse files Browse the repository at this point in the history
  • Loading branch information
slorello89 committed Jul 21, 2023
1 parent dc18a2b commit 57b74e5
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,11 @@ public RedisFuture<List<Object>> tsInfoDebug(K key) {
return dispatch(timeSeriesCommandBuilder.info(key, true));
}

@Override
public RedisFuture<List<V>> tsQueryIndex(V... filters){
return dispatch(timeSeriesCommandBuilder.queryIndex(filters));
}

@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 @@ -265,6 +265,9 @@ public Flux<Object> tsInfoDebug(K key) {
return createDissolvingFlux(() -> timeSeriesCommandBuilder.info(key, true));
}

@Override
public Flux<V> tsQueryIndex(V... filters){return createDissolvingFlux(()->timeSeriesCommandBuilder.queryIndex(filters));}

@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 @@ -77,4 +77,5 @@ public interface RedisTimeSeriesAsyncCommands<K, V> {

RedisFuture<List<Object>> tsInfoDebug(K key);

RedisFuture<List<V>> tsQueryIndex(V... filters);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.List;

@SuppressWarnings("unchecked")
public interface RedisTimeSeriesReactiveCommands<K, V> {

Expand Down Expand Up @@ -70,4 +72,5 @@ public interface RedisTimeSeriesReactiveCommands<K, V> {

Flux<Object> tsInfoDebug(K key);

Flux<V> tsQueryIndex(V... filters);
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,6 @@ public interface RedisTimeSeriesCommands<K, V> {
List<Object> tsInfo(K key);

List<Object> tsInfoDebug(K key);

List<V> tsQueryIndex(V... filter);
}
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,9 @@ public RedisFuture<List<Object>> tsInfoDebug(K key) {
return delegate.tsInfoDebug(key);
}

@Override
public RedisFuture<List<V>> tsQueryIndex(V... filters){return delegate.tsQueryIndex(filters);}

@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 @@ -439,6 +439,9 @@ public Flux<Object> tsInfoDebug(K key) {
return delegate.tsInfoDebug(key);
}

@Override
public Flux<V> tsQueryIndex(V... filters){ return delegate.tsQueryIndex(filters);}

@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;
ADD, ALTER, CREATE, CREATERULE, DELETERULE, MADD, INCRBY, DECRBY, RANGE, REVRANGE, MRANGE, MREVRANGE, GET, MGET, INFO, QUERYINDEX;

private static final String PREFIX = "TS.";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@
import com.redis.lettucemod.protocol.TimeSeriesCommandType;

import io.lettuce.core.codec.RedisCodec;
import io.lettuce.core.output.CommandOutput;
import io.lettuce.core.output.IntegerListOutput;
import io.lettuce.core.output.IntegerOutput;
import io.lettuce.core.output.NestedMultiOutput;
import io.lettuce.core.output.StatusOutput;
import io.lettuce.core.output.*;
import io.lettuce.core.protocol.Command;
import io.lettuce.core.protocol.CommandArgs;

Expand Down Expand Up @@ -211,4 +207,14 @@ public Command<K, V, List<Object>> info(K key, boolean debug) {
}
return createCommand(TimeSeriesCommandType.INFO, new NestedMultiOutput<>(codec), args);
}

public Command<K, V, List<V>> queryIndex(V... filters){
notNull(filters, "filters");
CommandArgs<K,V> args = new CommandArgs<>(codec);
for(V filter : filters){
args.add(filter.toString());
}

return createCommand(TimeSeriesCommandType.QUERYINDEX, new ValueListOutput<>(codec), args);
}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
package com.redis.lettucemod;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.stream.Collectors;

import com.redis.lettucemod.timeseries.*;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.redis.lettucemod.api.StatefulRedisModulesConnection;
import com.redis.lettucemod.api.sync.RedisModulesCommands;
import com.redis.lettucemod.api.sync.RedisTimeSeriesCommands;
import com.redis.lettucemod.timeseries.DuplicatePolicy;
import com.redis.lettucemod.timeseries.GetResult;
import com.redis.lettucemod.timeseries.Label;
import com.redis.lettucemod.timeseries.MRangeOptions;
import com.redis.lettucemod.timeseries.RangeResult;
import com.redis.lettucemod.timeseries.TimeRange;
import com.redis.lettucemod.util.ClientBuilder;
import com.redis.lettucemod.util.RedisModulesUtils;
import com.redis.lettucemod.util.RedisURIBuilder;
Expand Down Expand Up @@ -103,6 +100,22 @@ void tsCreate() {
assertEquals(expectedLabel, results.get(0).getLabels().get(0));
}

@Test
void tsQueryIndex(){
String key1 = "tsQueryIndex:key1";
String key2 = "tsQueryIndex:key2";
connection.sync().del(key1, key2);
String id = "tsQueryIndex";
List<Label<String,String>> labels = Collections.singletonList(Label.of("id", id));
assertEquals("OK",
connection.sync().tsCreate(key1, CreateOptions.<String, String>builder().labels(labels).build()));
assertEquals("OK",
connection.sync().tsCreate(key2, CreateOptions.<String, String>builder().labels(labels).build()));
List<String> res = connection.sync().tsQueryIndex(String.format("id=%s",id));
assertTrue(res.contains(key1));
assertTrue(res.contains(key2));
}

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

0 comments on commit 57b74e5

Please sign in to comment.