Skip to content

Commit

Permalink
Support IGNORE option
Browse files Browse the repository at this point in the history
and rename to TSIncrOrDecrByParams
  • Loading branch information
sazzad16 committed Jun 13, 2024
1 parent f084b18 commit 505023e
Show file tree
Hide file tree
Showing 13 changed files with 146 additions and 35 deletions.
4 changes: 2 additions & 2 deletions src/main/java/redis/clients/jedis/CommandObjects.java
Original file line number Diff line number Diff line change
Expand Up @@ -3974,7 +3974,7 @@ public final CommandObject<Long> tsIncrBy(String key, double value, long timesta
.add(TimeSeriesKeyword.TIMESTAMP).add(timestamp), BuilderFactory.LONG);
}

public final CommandObject<Long> tsIncrBy(String key, double addend, TSIncrByDecrByParams incrByParams) {
public final CommandObject<Long> tsIncrBy(String key, double addend, TSIncrOrDecrByParams incrByParams) {
return new CommandObject<>(commandArguments(TimeSeriesCommand.INCRBY).key(key).add(addend)
.addParams(incrByParams), BuilderFactory.LONG);
}
Expand All @@ -3988,7 +3988,7 @@ public final CommandObject<Long> tsDecrBy(String key, double value, long timesta
.add(TimeSeriesKeyword.TIMESTAMP).add(timestamp), BuilderFactory.LONG);
}

public final CommandObject<Long> tsDecrBy(String key, double subtrahend, TSIncrByDecrByParams decrByParams) {
public final CommandObject<Long> tsDecrBy(String key, double subtrahend, TSIncrOrDecrByParams decrByParams) {
return new CommandObject<>(commandArguments(TimeSeriesCommand.DECRBY).key(key).add(subtrahend)
.addParams(decrByParams), BuilderFactory.LONG);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/redis/clients/jedis/PipeliningBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -3969,7 +3969,7 @@ public Response<Long> tsIncrBy(String key, double value, long timestamp) {
}

@Override
public Response<Long> tsIncrBy(String key, double addend, TSIncrByDecrByParams incrByParams) {
public Response<Long> tsIncrBy(String key, double addend, TSIncrOrDecrByParams incrByParams) {
return appendCommand(commandObjects.tsIncrBy(key, addend, incrByParams));
}

Expand All @@ -3984,7 +3984,7 @@ public Response<Long> tsDecrBy(String key, double value, long timestamp) {
}

@Override
public Response<Long> tsDecrBy(String key, double subtrahend, TSIncrByDecrByParams decrByParams) {
public Response<Long> tsDecrBy(String key, double subtrahend, TSIncrOrDecrByParams decrByParams) {
return appendCommand(commandObjects.tsDecrBy(key, subtrahend, decrByParams));
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/redis/clients/jedis/UnifiedJedis.java
Original file line number Diff line number Diff line change
Expand Up @@ -4494,7 +4494,7 @@ public long tsIncrBy(String key, double value, long timestamp) {
}

@Override
public long tsIncrBy(String key, double addend, TSIncrByDecrByParams incrByParams) {
public long tsIncrBy(String key, double addend, TSIncrOrDecrByParams incrByParams) {
return executeCommand(commandObjects.tsIncrBy(key, addend, incrByParams));
}

Expand All @@ -4509,7 +4509,7 @@ public long tsDecrBy(String key, double value, long timestamp) {
}

@Override
public long tsDecrBy(String key, double subtrahend, TSIncrByDecrByParams decrByParams) {
public long tsDecrBy(String key, double subtrahend, TSIncrOrDecrByParams decrByParams) {
return executeCommand(commandObjects.tsDecrBy(key, subtrahend, decrByParams));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public interface RedisTimeSeriesCommands {
* @param incrByParams
* @return timestamp
*/
long tsIncrBy(String key, double addend, TSIncrByDecrByParams incrByParams);
long tsIncrBy(String key, double addend, TSIncrOrDecrByParams incrByParams);

long tsDecrBy(String key, double value);

Expand All @@ -134,7 +134,7 @@ public interface RedisTimeSeriesCommands {
* @param decrByParams
* @return timestamp
*/
long tsDecrBy(String key, double subtrahend, TSIncrByDecrByParams decrByParams);
long tsDecrBy(String key, double subtrahend, TSIncrOrDecrByParams decrByParams);

/**
* {@code TS.RANGE key fromTimestamp toTimestamp}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ public interface RedisTimeSeriesPipelineCommands {

Response<Long> tsIncrBy(String key, double value, long timestamp);

Response<Long> tsIncrBy(String key, double addend, TSIncrByDecrByParams incrByParams);
Response<Long> tsIncrBy(String key, double addend, TSIncrOrDecrByParams incrByParams);

Response<Long> tsDecrBy(String key, double value);

Response<Long> tsDecrBy(String key, double value, long timestamp);

Response<Long> tsDecrBy(String key, double subtrahend, TSIncrByDecrByParams decrByParams);
Response<Long> tsDecrBy(String key, double subtrahend, TSIncrOrDecrByParams decrByParams);

Response<List<TSElement>> tsRange(String key, long fromTimestamp, long toTimestamp);

Expand Down
19 changes: 19 additions & 0 deletions src/main/java/redis/clients/jedis/timeseries/TSAddParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ public class TSAddParams implements IParams {
private Long chunkSize;
private DuplicatePolicy duplicatePolicy;
private DuplicatePolicy onDuplicate;

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

private Map<String, String> labels;

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

public TSAddParams 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 TSAddParams 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 TSAddParams label(String label, String value) {
if (this.labels == null) {
Expand Down Expand Up @@ -101,6 +116,10 @@ public void addParams(CommandArguments args) {
args.add(ON_DUPLICATE).add(onDuplicate);
}

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
28 changes: 28 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,11 +46,30 @@ 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;
}

/**
* Set label-value pairs
*
* @param labels label-value pairs
* @return the object itself
*/
public TSAlterParams labels(Map<String, String> labels) {
this.labels = labels;
return this;
}

/**
* Add label-value pair. Multiple pairs can be added through chaining.
* @param label
* @param value
* @return the object itself
*/
public TSAlterParams label(String label, String value) {
if (this.labels == null) {
this.labels = new LinkedHashMap<>();
Expand Down Expand Up @@ -73,6 +97,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 @@ -17,6 +17,11 @@ public class TSCreateParams implements IParams {
private EncodingFormat encoding;
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 @@ -56,6 +61,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 @@ -69,6 +81,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 @@ -97,6 +112,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 @@ -11,62 +11,85 @@
/**
* Represents optional arguments of TS.INCRBY or TS.DECRBY commands.
*/
public class TSIncrByDecrByParams implements IParams {
public class TSIncrOrDecrByParams implements IParams {

private Long timestamp;
private Long retentionPeriod;
private EncodingFormat encoding;
private Long chunkSize;
private DuplicatePolicy duplicatePolicy;

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

private Map<String, String> labels;

public TSIncrByDecrByParams() {
public TSIncrOrDecrByParams() {
}

public static TSIncrOrDecrByParams params() {
return new TSIncrOrDecrByParams();
}

public static TSIncrOrDecrByParams incrByParams() {
return new TSIncrOrDecrByParams();
}

public static TSIncrByDecrByParams params() {
return new TSIncrByDecrByParams();
public static TSIncrOrDecrByParams decrByParams() {
return new TSIncrOrDecrByParams();
}

public TSIncrByDecrByParams timestamp(long timestamp) {
public TSIncrOrDecrByParams timestamp(long timestamp) {
this.timestamp = timestamp;
return this;
}

public TSIncrByDecrByParams retention(long retentionPeriod) {
public TSIncrOrDecrByParams retention(long retentionPeriod) {
this.retentionPeriod = retentionPeriod;
return this;
}

public TSIncrByDecrByParams encoding(EncodingFormat encoding) {
public TSIncrOrDecrByParams encoding(EncodingFormat encoding) {
this.encoding = encoding;
return this;
}

public TSIncrByDecrByParams chunkSize(long chunkSize) {
public TSIncrOrDecrByParams chunkSize(long chunkSize) {
this.chunkSize = chunkSize;
return this;
}

public TSIncrByDecrByParams duplicatePolicy(DuplicatePolicy duplicatePolicy) {
public TSIncrOrDecrByParams duplicatePolicy(DuplicatePolicy duplicatePolicy) {
this.duplicatePolicy = duplicatePolicy;
return this;
}

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

/**
* Set label-value pairs
*
* @param labels label-value pairs
* @return the object itself
*/
public TSIncrByDecrByParams labels(Map<String, String> labels) {
public TSIncrOrDecrByParams labels(Map<String, String> labels) {
this.labels = labels;
return this;
}

/**
* Add label-value pair. Multiple pairs can be added through chaining.
* @param label
* @param value
* @return the object itself
*/
public TSIncrByDecrByParams label(String label, String value) {
public TSIncrOrDecrByParams label(String label, String value) {
if (this.labels == null) {
this.labels = new LinkedHashMap<>();
}
Expand Down Expand Up @@ -97,6 +120,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 @@ -143,7 +143,7 @@ public void testTsDecrByWithTimestamp() {

@Test
public void testTsDecrByWithParams() {
TSIncrByDecrByParams DecrByParams = mock(TSIncrByDecrByParams.class);
TSIncrOrDecrByParams DecrByParams = mock(TSIncrOrDecrByParams.class);
when(commandObjects.tsDecrBy("myTimeSeries", 1.0, DecrByParams)).thenReturn(longCommandObject);

Response<Long> response = pipeliningBase.tsDecrBy("myTimeSeries", 1.0, DecrByParams);
Expand Down Expand Up @@ -216,7 +216,7 @@ public void testTsIncrByWithTimestamp() {

@Test
public void testTsIncrByWithParams() {
TSIncrByDecrByParams incrByParams = mock(TSIncrByDecrByParams.class);
TSIncrOrDecrByParams incrByParams = mock(TSIncrOrDecrByParams.class);
when(commandObjects.tsIncrBy("myTimeSeries", 1.0, incrByParams)).thenReturn(longCommandObject);

Response<Long> response = pipeliningBase.tsIncrBy("myTimeSeries", 1.0, incrByParams);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public void testTsDecrByWithTimestamp() {
public void testTsDecrByWithParams() {
String key = "testKey";
double value = 1.5;
TSIncrByDecrByParams decrByParams = mock(TSIncrByDecrByParams.class);
TSIncrOrDecrByParams decrByParams = mock(TSIncrOrDecrByParams.class);
long expectedResponse = 5L;

when(commandObjects.tsDecrBy(key, value, decrByParams)).thenReturn(longCommandObject);
Expand Down Expand Up @@ -341,7 +341,7 @@ public void testTsIncrByWithTimestamp() {
public void testTsIncrByWithParams() {
String key = "testKey";
double value = 2.5;
TSIncrByDecrByParams incrByParams = mock(TSIncrByDecrByParams.class);
TSIncrOrDecrByParams incrByParams = mock(TSIncrOrDecrByParams.class);
long expectedResponse = 5L;

when(commandObjects.tsIncrBy(key, value, incrByParams)).thenReturn(longCommandObject);
Expand Down
Loading

0 comments on commit 505023e

Please sign in to comment.