Skip to content

Commit

Permalink
Support IGNORE argument in TimeSeries commands
Browse files Browse the repository at this point in the history
  • Loading branch information
sazzad16 committed May 5, 2024
1 parent dfb1640 commit c9b19fd
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@ public interface RedisTimeSeriesCommands {
String tsCreate(String key);

/**
* {@code TS.CREATE key [RETENTION retentionTime] [ENCODING [UNCOMPRESSED|COMPRESSED]] [CHUNK_SIZE size] [DUPLICATE_POLICY policy] [LABELS label value..]}
* {@code
* TS.CREATE key
* [RETENTION retentionTime]
* [ENCODING [UNCOMPRESSED|COMPRESSED]]
* [CHUNK_SIZE size]
* [DUPLICATE_POLICY policy]
* [IGNORE ignoreMaxTimediff ignoreMaxValDiff]
* [LABELS {label value}...]
* }
*
* @param key
* @param createParams
Expand All @@ -31,7 +39,13 @@ public interface RedisTimeSeriesCommands {
long tsDel(String key, long fromTimestamp, long toTimestamp);

/**
* {@code TS.ALTER key [RETENTION retentionTime] [LABELS label value..]}
* {@code TS.ALTER key
* [RETENTION retentionTime]
* [CHUNK_SIZE size]
* [DUPLICATE_POLICY policy]
* [IGNORE ignoreMaxTimediff ignoreMaxValDiff]
* [LABELS {label value}...]
* }
*
* @param key
* @param alterParams
Expand Down Expand Up @@ -59,7 +73,14 @@ public interface RedisTimeSeriesCommands {
long tsAdd(String key, long timestamp, double value);

/**
* {@code TS.ADD key timestamp value [RETENTION retentionTime] [ENCODING [COMPRESSED|UNCOMPRESSED]] [CHUNK_SIZE size] [ON_DUPLICATE policy] [LABELS label value..]}
* {@code TS.ADD key timestamp value
* [RETENTION retentionTime]
* [ENCODING [UNCOMPRESSED|COMPRESSED]]
* [CHUNK_SIZE size]
* [DUPLICATE_POLICY policy]
* [IGNORE ignoreMaxTimediff ignoreMaxValDiff]
* [LABELS {label value}...]
* }
*
* @param key
* @param timestamp
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/redis/clients/jedis/timeseries/TSAlterParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public class TSAlterParams implements IParams {
private Long retentionPeriod;
private Long chunkSize;
private DuplicatePolicy duplicatePolicy;

private boolean ignore;
private long ignoreMaxTimediff;
private double ignoreMaxValDiff;

private Map<String, String> labels;

public TSAlterParams() {
Expand All @@ -41,6 +46,13 @@ public TSAlterParams duplicatePolicy(DuplicatePolicy duplicatePolicy) {
return this;
}

public TSAlterParams ignore(long maxTimediff, double maxValDiff) {
this.ignore = true;
this.ignoreMaxTimediff = maxTimediff;
this.ignoreMaxValDiff = maxValDiff;
return this;
}

public TSAlterParams labels(Map<String, String> labels) {
this.labels = labels;
return this;
Expand Down Expand Up @@ -73,6 +85,10 @@ public void addParams(CommandArguments args) {
args.add(DUPLICATE_POLICY).add(duplicatePolicy);
}

if (ignore) {
args.add(IGNORE).add(ignoreMaxTimediff).add(ignoreMaxValDiff);
}

if (labels != null) {
args.add(LABELS);
labels.entrySet().forEach((entry) -> args.add(entry.getKey()).add(entry.getValue()));
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/redis/clients/jedis/timeseries/TSCreateParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ public class TSCreateParams implements IParams {
private boolean compressed;
private Long chunkSize;
private DuplicatePolicy duplicatePolicy;

private boolean ignore;
private long ignoreMaxTimediff;
private double ignoreMaxValDiff;

private Map<String, String> labels;

public TSCreateParams() {
Expand Down Expand Up @@ -52,6 +57,13 @@ public TSCreateParams duplicatePolicy(DuplicatePolicy duplicatePolicy) {
return this;
}

public TSCreateParams ignore(long maxTimediff, double maxValDiff) {
this.ignore = true;
this.ignoreMaxTimediff = maxTimediff;
this.ignoreMaxValDiff = maxValDiff;
return this;
}

/**
* Set label-value pairs
*
Expand All @@ -65,6 +77,9 @@ public TSCreateParams labels(Map<String, String> labels) {

/**
* Add label-value pair. Multiple pairs can be added through chaining.
* @param label
* @param value
* @return the object itself
*/
public TSCreateParams label(String label, String value) {
if (this.labels == null) {
Expand Down Expand Up @@ -95,6 +110,10 @@ public void addParams(CommandArguments args) {
args.add(DUPLICATE_POLICY).add(duplicatePolicy);
}

if (ignore) {
args.add(IGNORE).add(ignoreMaxTimediff).add(ignoreMaxValDiff);
}

if (labels != null) {
args.add(LABELS);
labels.entrySet().forEach((entry) -> args.add(entry.getKey()).add(entry.getValue()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public enum TimeSeriesKeyword implements Rawable {
UNCOMPRESSED,
CHUNK_SIZE,
DUPLICATE_POLICY,
IGNORE,
ON_DUPLICATE,
ALIGN,
FILTER_BY_TS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,39 @@ public void testAdd() {
}
}

@Test
public void testCreateIgnore() {
assertEquals("OK", client.tsCreate("series-ignore",
TSCreateParams.createParams().ignore(5, 2)));
//System.out.println(client.tsInfo("series-ignore").getProperties()); // doesn't provide IGNORE info

client.tsAdd("series-ignore", 0, 0);
System.out.println(client.tsAdd("series-ignore", 100, 20)); // should fail, doesn't fail
// TODO: complete tests
}

@Test
public void testAlterIgnore() {
assertEquals("OK", client.tsCreate("series-ignore"));
assertEquals("OK", client.tsAlter("series-ignore",
TSAlterParams.alterParams().ignore(5, 2)));
//System.out.println(client.tsInfo("series-ignore").getProperties()); // doesn't provide IGNORE info

client.tsAdd("series-ignore", 0, 0);
System.out.println(client.tsAdd("series-ignore", 100, 20)); // should fail, doesn't fail
// TODO: complete tests
}

@Test
public void testAddIgnore() {
assertEquals(0, client.tsAdd("series-ignore", 0, 0,
TSCreateParams.createParams().ignore(5, 2)));
//System.out.println(client.tsInfo("series-ignore").getProperties()); // doesn't provide IGNORE info

System.out.println(client.tsAdd("series-ignore", 100, 20)); // should fail, doesn't fail
// TODO: complete tests
}

@Test
public void issue75() {
client.tsMRange(TSMRangeParams.multiRangeParams().filter("id=1"));
Expand Down

0 comments on commit c9b19fd

Please sign in to comment.