diff --git a/src/main/java/redis/clients/jedis/timeseries/RedisTimeSeriesCommands.java b/src/main/java/redis/clients/jedis/timeseries/RedisTimeSeriesCommands.java index c002b94c08..d1cbbffd6f 100644 --- a/src/main/java/redis/clients/jedis/timeseries/RedisTimeSeriesCommands.java +++ b/src/main/java/redis/clients/jedis/timeseries/RedisTimeSeriesCommands.java @@ -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 @@ -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 @@ -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 diff --git a/src/main/java/redis/clients/jedis/timeseries/TSAlterParams.java b/src/main/java/redis/clients/jedis/timeseries/TSAlterParams.java index 4576a1b6b7..9ec3b8e63b 100644 --- a/src/main/java/redis/clients/jedis/timeseries/TSAlterParams.java +++ b/src/main/java/redis/clients/jedis/timeseries/TSAlterParams.java @@ -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 labels; public TSAlterParams() { @@ -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 labels) { this.labels = labels; return this; @@ -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())); diff --git a/src/main/java/redis/clients/jedis/timeseries/TSCreateParams.java b/src/main/java/redis/clients/jedis/timeseries/TSCreateParams.java index ca07de1f01..e71d042bd7 100644 --- a/src/main/java/redis/clients/jedis/timeseries/TSCreateParams.java +++ b/src/main/java/redis/clients/jedis/timeseries/TSCreateParams.java @@ -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 labels; public TSCreateParams() { @@ -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 * @@ -65,6 +77,9 @@ public TSCreateParams labels(Map 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) { @@ -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())); diff --git a/src/main/java/redis/clients/jedis/timeseries/TimeSeriesProtocol.java b/src/main/java/redis/clients/jedis/timeseries/TimeSeriesProtocol.java index 2476979f0d..384a454921 100644 --- a/src/main/java/redis/clients/jedis/timeseries/TimeSeriesProtocol.java +++ b/src/main/java/redis/clients/jedis/timeseries/TimeSeriesProtocol.java @@ -57,6 +57,7 @@ public enum TimeSeriesKeyword implements Rawable { UNCOMPRESSED, CHUNK_SIZE, DUPLICATE_POLICY, + IGNORE, ON_DUPLICATE, ALIGN, FILTER_BY_TS, diff --git a/src/test/java/redis/clients/jedis/modules/timeseries/TimeSeriesTest.java b/src/test/java/redis/clients/jedis/modules/timeseries/TimeSeriesTest.java index fe0f7d1604..d86ae2ab92 100644 --- a/src/test/java/redis/clients/jedis/modules/timeseries/TimeSeriesTest.java +++ b/src/test/java/redis/clients/jedis/modules/timeseries/TimeSeriesTest.java @@ -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"));