Skip to content

Commit

Permalink
Polish #3860: Separate params for TS.INCRBY and TS.DECRBY (#3863)
Browse files Browse the repository at this point in the history
  • Loading branch information
sazzad16 committed Jul 10, 2024
1 parent 1c3df87 commit df6d2f2
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 44 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 @@ -3969,7 +3969,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, TSIncrOrDecrByParams incrByParams) {
public final CommandObject<Long> tsIncrBy(String key, double addend, TSIncrByParams incrByParams) {
return new CommandObject<>(commandArguments(TimeSeriesCommand.INCRBY).key(key).add(addend)
.addParams(incrByParams), BuilderFactory.LONG);
}
Expand All @@ -3983,7 +3983,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, TSIncrOrDecrByParams decrByParams) {
public final CommandObject<Long> tsDecrBy(String key, double subtrahend, TSDecrByParams 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 @@ -3951,7 +3951,7 @@ public Response<Long> tsIncrBy(String key, double value, long timestamp) {
}

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

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

@Override
public Response<Long> tsDecrBy(String key, double subtrahend, TSIncrOrDecrByParams decrByParams) {
public Response<Long> tsDecrBy(String key, double subtrahend, TSDecrByParams 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 @@ -4482,7 +4482,7 @@ public long tsIncrBy(String key, double value, long timestamp) {
}

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

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

@Override
public long tsDecrBy(String key, double subtrahend, TSIncrOrDecrByParams decrByParams) {
public long tsDecrBy(String key, double subtrahend, TSDecrByParams 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, TSIncrOrDecrByParams incrByParams);
long tsIncrBy(String key, double addend, TSIncrByParams 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, TSIncrOrDecrByParams decrByParams);
long tsDecrBy(String key, double subtrahend, TSDecrByParams 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, TSIncrOrDecrByParams incrByParams);
Response<Long> tsIncrBy(String key, double addend, TSIncrByParams incrByParams);

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

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

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/**
* Represents optional arguments of TS.INCRBY or TS.DECRBY commands.
*/
public class TSIncrOrDecrByParams implements IParams {
class TSArithByParams<T extends TSArithByParams<?>> implements IParams {

private Long timestamp;
private Long retentionPeriod;
Expand All @@ -25,51 +25,39 @@ public class TSIncrOrDecrByParams implements IParams {

private Map<String, String> labels;

public TSIncrOrDecrByParams() {
TSArithByParams() {
}

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

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

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

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

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

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

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

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

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

/**
Expand All @@ -78,9 +66,9 @@ public TSIncrOrDecrByParams ignore(long maxTimediff, double maxValDiff) {
* @param labels label-value pairs
* @return the object itself
*/
public TSIncrOrDecrByParams labels(Map<String, String> labels) {
public T labels(Map<String, String> labels) {
this.labels = labels;
return this;
return (T) this;
}

/**
Expand All @@ -89,12 +77,12 @@ public TSIncrOrDecrByParams labels(Map<String, String> labels) {
* @param value
* @return the object itself
*/
public TSIncrOrDecrByParams label(String label, String value) {
public T label(String label, String value) {
if (this.labels == null) {
this.labels = new LinkedHashMap<>();
}
this.labels.put(label, value);
return this;
return (T) this;
}

@Override
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/redis/clients/jedis/timeseries/TSDecrByParams.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package redis.clients.jedis.timeseries;

/**
* Represents optional arguments of TS.DECRBY command.
*/
public class TSDecrByParams extends TSArithByParams<TSDecrByParams> {

public TSDecrByParams() {
}

public static TSDecrByParams decrByParams() {
return new TSDecrByParams();
}
}
14 changes: 14 additions & 0 deletions src/main/java/redis/clients/jedis/timeseries/TSIncrByParams.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package redis.clients.jedis.timeseries;

/**
* Represents optional arguments of TS.INCRBY command.
*/
public class TSIncrByParams extends TSArithByParams<TSIncrByParams> {

public TSIncrByParams() {
}

public static TSIncrByParams incrByParams() {
return new TSIncrByParams();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -446,19 +446,19 @@ public void incrByDecrByParams() {
labels.put("l2", "v2");

assertEquals(1000L, client.tsIncrBy("incr1", 1.1,
TSIncrOrDecrByParams.incrByParams().timestamp(1000).retention(10000).encoding(EncodingFormat.UNCOMPRESSED)
TSIncrByParams.incrByParams().timestamp(1000).retention(10000).encoding(EncodingFormat.UNCOMPRESSED)
.chunkSize(1000).duplicatePolicy(DuplicatePolicy.FIRST).ignore(50, 12.5).labels(labels)));

assertEquals(1000L, client.tsIncrBy("incr2", 1.1,
TSIncrOrDecrByParams.incrByParams().timestamp(1000).retention(10000).encoding(EncodingFormat.COMPRESSED)
TSIncrByParams.incrByParams().timestamp(1000).retention(10000).encoding(EncodingFormat.COMPRESSED)
.chunkSize(1000).duplicatePolicy(DuplicatePolicy.MIN).ignore(50, 12.5).labels(labels)));

assertEquals(1000L, client.tsDecrBy("decr1", 1.1,
TSIncrOrDecrByParams.decrByParams().timestamp(1000).retention(10000).encoding(EncodingFormat.COMPRESSED)
TSDecrByParams.decrByParams().timestamp(1000).retention(10000).encoding(EncodingFormat.COMPRESSED)
.chunkSize(1000).duplicatePolicy(DuplicatePolicy.LAST).ignore(50, 12.5).labels(labels)));

assertEquals(1000L, client.tsDecrBy("decr2", 1.1,
TSIncrOrDecrByParams.decrByParams().timestamp(1000).retention(10000).encoding(EncodingFormat.UNCOMPRESSED)
TSDecrByParams.decrByParams().timestamp(1000).retention(10000).encoding(EncodingFormat.UNCOMPRESSED)
.chunkSize(1000).duplicatePolicy(DuplicatePolicy.MAX).ignore(50, 12.5).labels(labels)));
}

Expand Down

0 comments on commit df6d2f2

Please sign in to comment.