Skip to content

Commit df6d2f2

Browse files
committed
Polish #3860: Separate params for TS.INCRBY and TS.DECRBY (#3863)
1 parent 1c3df87 commit df6d2f2

File tree

9 files changed

+60
-44
lines changed

9 files changed

+60
-44
lines changed

src/main/java/redis/clients/jedis/CommandObjects.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3969,7 +3969,7 @@ public final CommandObject<Long> tsIncrBy(String key, double value, long timesta
39693969
.add(TimeSeriesKeyword.TIMESTAMP).add(timestamp), BuilderFactory.LONG);
39703970
}
39713971

3972-
public final CommandObject<Long> tsIncrBy(String key, double addend, TSIncrOrDecrByParams incrByParams) {
3972+
public final CommandObject<Long> tsIncrBy(String key, double addend, TSIncrByParams incrByParams) {
39733973
return new CommandObject<>(commandArguments(TimeSeriesCommand.INCRBY).key(key).add(addend)
39743974
.addParams(incrByParams), BuilderFactory.LONG);
39753975
}
@@ -3983,7 +3983,7 @@ public final CommandObject<Long> tsDecrBy(String key, double value, long timesta
39833983
.add(TimeSeriesKeyword.TIMESTAMP).add(timestamp), BuilderFactory.LONG);
39843984
}
39853985

3986-
public final CommandObject<Long> tsDecrBy(String key, double subtrahend, TSIncrOrDecrByParams decrByParams) {
3986+
public final CommandObject<Long> tsDecrBy(String key, double subtrahend, TSDecrByParams decrByParams) {
39873987
return new CommandObject<>(commandArguments(TimeSeriesCommand.DECRBY).key(key).add(subtrahend)
39883988
.addParams(decrByParams), BuilderFactory.LONG);
39893989
}

src/main/java/redis/clients/jedis/PipeliningBase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3951,7 +3951,7 @@ public Response<Long> tsIncrBy(String key, double value, long timestamp) {
39513951
}
39523952

39533953
@Override
3954-
public Response<Long> tsIncrBy(String key, double addend, TSIncrOrDecrByParams incrByParams) {
3954+
public Response<Long> tsIncrBy(String key, double addend, TSIncrByParams incrByParams) {
39553955
return appendCommand(commandObjects.tsIncrBy(key, addend, incrByParams));
39563956
}
39573957

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

39683968
@Override
3969-
public Response<Long> tsDecrBy(String key, double subtrahend, TSIncrOrDecrByParams decrByParams) {
3969+
public Response<Long> tsDecrBy(String key, double subtrahend, TSDecrByParams decrByParams) {
39703970
return appendCommand(commandObjects.tsDecrBy(key, subtrahend, decrByParams));
39713971
}
39723972

src/main/java/redis/clients/jedis/UnifiedJedis.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4482,7 +4482,7 @@ public long tsIncrBy(String key, double value, long timestamp) {
44824482
}
44834483

44844484
@Override
4485-
public long tsIncrBy(String key, double addend, TSIncrOrDecrByParams incrByParams) {
4485+
public long tsIncrBy(String key, double addend, TSIncrByParams incrByParams) {
44864486
return executeCommand(commandObjects.tsIncrBy(key, addend, incrByParams));
44874487
}
44884488

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

44994499
@Override
4500-
public long tsDecrBy(String key, double subtrahend, TSIncrOrDecrByParams decrByParams) {
4500+
public long tsDecrBy(String key, double subtrahend, TSDecrByParams decrByParams) {
45014501
return executeCommand(commandObjects.tsDecrBy(key, subtrahend, decrByParams));
45024502
}
45034503

src/main/java/redis/clients/jedis/timeseries/RedisTimeSeriesCommands.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public interface RedisTimeSeriesCommands {
113113
* @param incrByParams
114114
* @return timestamp
115115
*/
116-
long tsIncrBy(String key, double addend, TSIncrOrDecrByParams incrByParams);
116+
long tsIncrBy(String key, double addend, TSIncrByParams incrByParams);
117117

118118
long tsDecrBy(String key, double value);
119119

@@ -134,7 +134,7 @@ public interface RedisTimeSeriesCommands {
134134
* @param decrByParams
135135
* @return timestamp
136136
*/
137-
long tsDecrBy(String key, double subtrahend, TSIncrOrDecrByParams decrByParams);
137+
long tsDecrBy(String key, double subtrahend, TSDecrByParams decrByParams);
138138

139139
/**
140140
* {@code TS.RANGE key fromTimestamp toTimestamp}

src/main/java/redis/clients/jedis/timeseries/RedisTimeSeriesPipelineCommands.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ public interface RedisTimeSeriesPipelineCommands {
2929

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

32-
Response<Long> tsIncrBy(String key, double addend, TSIncrOrDecrByParams incrByParams);
32+
Response<Long> tsIncrBy(String key, double addend, TSIncrByParams incrByParams);
3333

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

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

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

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

src/main/java/redis/clients/jedis/timeseries/TSIncrOrDecrByParams.java renamed to src/main/java/redis/clients/jedis/timeseries/TSArithByParams.java

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
/**
1212
* Represents optional arguments of TS.INCRBY or TS.DECRBY commands.
1313
*/
14-
public class TSIncrOrDecrByParams implements IParams {
14+
class TSArithByParams<T extends TSArithByParams<?>> implements IParams {
1515

1616
private Long timestamp;
1717
private Long retentionPeriod;
@@ -25,51 +25,39 @@ public class TSIncrOrDecrByParams implements IParams {
2525

2626
private Map<String, String> labels;
2727

28-
public TSIncrOrDecrByParams() {
28+
TSArithByParams() {
2929
}
3030

31-
public static TSIncrOrDecrByParams params() {
32-
return new TSIncrOrDecrByParams();
33-
}
34-
35-
public static TSIncrOrDecrByParams incrByParams() {
36-
return new TSIncrOrDecrByParams();
37-
}
38-
39-
public static TSIncrOrDecrByParams decrByParams() {
40-
return new TSIncrOrDecrByParams();
41-
}
42-
43-
public TSIncrOrDecrByParams timestamp(long timestamp) {
31+
public T timestamp(long timestamp) {
4432
this.timestamp = timestamp;
45-
return this;
33+
return (T) this;
4634
}
4735

48-
public TSIncrOrDecrByParams retention(long retentionPeriod) {
36+
public T retention(long retentionPeriod) {
4937
this.retentionPeriod = retentionPeriod;
50-
return this;
38+
return (T) this;
5139
}
5240

53-
public TSIncrOrDecrByParams encoding(EncodingFormat encoding) {
41+
public T encoding(EncodingFormat encoding) {
5442
this.encoding = encoding;
55-
return this;
43+
return (T) this;
5644
}
5745

58-
public TSIncrOrDecrByParams chunkSize(long chunkSize) {
46+
public T chunkSize(long chunkSize) {
5947
this.chunkSize = chunkSize;
60-
return this;
48+
return (T) this;
6149
}
6250

63-
public TSIncrOrDecrByParams duplicatePolicy(DuplicatePolicy duplicatePolicy) {
51+
public T duplicatePolicy(DuplicatePolicy duplicatePolicy) {
6452
this.duplicatePolicy = duplicatePolicy;
65-
return this;
53+
return (T) this;
6654
}
6755

68-
public TSIncrOrDecrByParams ignore(long maxTimediff, double maxValDiff) {
56+
public T ignore(long maxTimediff, double maxValDiff) {
6957
this.ignore = true;
7058
this.ignoreMaxTimediff = maxTimediff;
7159
this.ignoreMaxValDiff = maxValDiff;
72-
return this;
60+
return (T) this;
7361
}
7462

7563
/**
@@ -78,9 +66,9 @@ public TSIncrOrDecrByParams ignore(long maxTimediff, double maxValDiff) {
7866
* @param labels label-value pairs
7967
* @return the object itself
8068
*/
81-
public TSIncrOrDecrByParams labels(Map<String, String> labels) {
69+
public T labels(Map<String, String> labels) {
8270
this.labels = labels;
83-
return this;
71+
return (T) this;
8472
}
8573

8674
/**
@@ -89,12 +77,12 @@ public TSIncrOrDecrByParams labels(Map<String, String> labels) {
8977
* @param value
9078
* @return the object itself
9179
*/
92-
public TSIncrOrDecrByParams label(String label, String value) {
80+
public T label(String label, String value) {
9381
if (this.labels == null) {
9482
this.labels = new LinkedHashMap<>();
9583
}
9684
this.labels.put(label, value);
97-
return this;
85+
return (T) this;
9886
}
9987

10088
@Override
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package redis.clients.jedis.timeseries;
2+
3+
/**
4+
* Represents optional arguments of TS.DECRBY command.
5+
*/
6+
public class TSDecrByParams extends TSArithByParams<TSDecrByParams> {
7+
8+
public TSDecrByParams() {
9+
}
10+
11+
public static TSDecrByParams decrByParams() {
12+
return new TSDecrByParams();
13+
}
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package redis.clients.jedis.timeseries;
2+
3+
/**
4+
* Represents optional arguments of TS.INCRBY command.
5+
*/
6+
public class TSIncrByParams extends TSArithByParams<TSIncrByParams> {
7+
8+
public TSIncrByParams() {
9+
}
10+
11+
public static TSIncrByParams incrByParams() {
12+
return new TSIncrByParams();
13+
}
14+
}

src/test/java/redis/clients/jedis/modules/timeseries/TimeSeriesTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -446,19 +446,19 @@ public void incrByDecrByParams() {
446446
labels.put("l2", "v2");
447447

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

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

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

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

0 commit comments

Comments
 (0)