Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support IGNORE argument in TimeSeries commands #3830

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
sazzad16 marked this conversation as resolved.
Show resolved Hide resolved

/**
* {@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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TS.INCRBY and TS.DECRBY should also be updated

* [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;
sazzad16 marked this conversation as resolved.
Show resolved Hide resolved
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;
sazzad16 marked this conversation as resolved.
Show resolved Hide resolved
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,25 @@ public void testAdd() {
}
}

@Test
public void testCreateIgnore() {
assertEquals("OK", client.tsCreate("series-ignore",
TSCreateParams.createParams().ignore(5, 3)));
//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", 1, 1)); // should be ignored? doesn't get ignored
System.out.println(client.tsGet("series-ignore")); // >> (1:1.0)
System.out.println(client.tsRange("series-ignore", 0, 1000)); // >> [(0:0.0), (1:1.0)]
System.out.println(client.tsInfo("series-ignore").getProperties().get("totalSamples")); // >> 2
System.out.println(client.tsAdd("series-ignore", 100, 20)); // should be ignored, doesn't get ignored
System.out.println(client.tsGet("series-ignore")); // >> (100:20.0)
System.out.println(client.tsRange("series-ignore", 0, 1000)); // >> [(0:0.0), (1:1.0), (100:20.0)]
System.out.println(client.tsInfo("series-ignore").getProperties().get("totalSamples")); // >> 3
// TODO: complete test
}
// TODO: more tests from TS.ALTER and TS.ADD instead of TS.CREATE.

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