From df6d2f2b401bb9f6f029630577a092d349913f2e Mon Sep 17 00:00:00 2001 From: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com> Date: Fri, 14 Jun 2024 19:59:25 +0600 Subject: [PATCH] Polish #3860: Separate params for TS.INCRBY and TS.DECRBY (#3863) --- .../redis/clients/jedis/CommandObjects.java | 4 +- .../redis/clients/jedis/PipeliningBase.java | 4 +- .../redis/clients/jedis/UnifiedJedis.java | 4 +- .../timeseries/RedisTimeSeriesCommands.java | 4 +- .../RedisTimeSeriesPipelineCommands.java | 4 +- ...DecrByParams.java => TSArithByParams.java} | 48 +++++++------------ .../jedis/timeseries/TSDecrByParams.java | 14 ++++++ .../jedis/timeseries/TSIncrByParams.java | 14 ++++++ .../modules/timeseries/TimeSeriesTest.java | 8 ++-- 9 files changed, 60 insertions(+), 44 deletions(-) rename src/main/java/redis/clients/jedis/timeseries/{TSIncrOrDecrByParams.java => TSArithByParams.java} (67%) create mode 100644 src/main/java/redis/clients/jedis/timeseries/TSDecrByParams.java create mode 100644 src/main/java/redis/clients/jedis/timeseries/TSIncrByParams.java diff --git a/src/main/java/redis/clients/jedis/CommandObjects.java b/src/main/java/redis/clients/jedis/CommandObjects.java index f93932becb..a413086f82 100644 --- a/src/main/java/redis/clients/jedis/CommandObjects.java +++ b/src/main/java/redis/clients/jedis/CommandObjects.java @@ -3969,7 +3969,7 @@ public final CommandObject tsIncrBy(String key, double value, long timesta .add(TimeSeriesKeyword.TIMESTAMP).add(timestamp), BuilderFactory.LONG); } - public final CommandObject tsIncrBy(String key, double addend, TSIncrOrDecrByParams incrByParams) { + public final CommandObject tsIncrBy(String key, double addend, TSIncrByParams incrByParams) { return new CommandObject<>(commandArguments(TimeSeriesCommand.INCRBY).key(key).add(addend) .addParams(incrByParams), BuilderFactory.LONG); } @@ -3983,7 +3983,7 @@ public final CommandObject tsDecrBy(String key, double value, long timesta .add(TimeSeriesKeyword.TIMESTAMP).add(timestamp), BuilderFactory.LONG); } - public final CommandObject tsDecrBy(String key, double subtrahend, TSIncrOrDecrByParams decrByParams) { + public final CommandObject tsDecrBy(String key, double subtrahend, TSDecrByParams decrByParams) { return new CommandObject<>(commandArguments(TimeSeriesCommand.DECRBY).key(key).add(subtrahend) .addParams(decrByParams), BuilderFactory.LONG); } diff --git a/src/main/java/redis/clients/jedis/PipeliningBase.java b/src/main/java/redis/clients/jedis/PipeliningBase.java index d37e11ad1a..296a58e9c6 100644 --- a/src/main/java/redis/clients/jedis/PipeliningBase.java +++ b/src/main/java/redis/clients/jedis/PipeliningBase.java @@ -3951,7 +3951,7 @@ public Response tsIncrBy(String key, double value, long timestamp) { } @Override - public Response tsIncrBy(String key, double addend, TSIncrOrDecrByParams incrByParams) { + public Response tsIncrBy(String key, double addend, TSIncrByParams incrByParams) { return appendCommand(commandObjects.tsIncrBy(key, addend, incrByParams)); } @@ -3966,7 +3966,7 @@ public Response tsDecrBy(String key, double value, long timestamp) { } @Override - public Response tsDecrBy(String key, double subtrahend, TSIncrOrDecrByParams decrByParams) { + public Response tsDecrBy(String key, double subtrahend, TSDecrByParams decrByParams) { return appendCommand(commandObjects.tsDecrBy(key, subtrahend, decrByParams)); } diff --git a/src/main/java/redis/clients/jedis/UnifiedJedis.java b/src/main/java/redis/clients/jedis/UnifiedJedis.java index c319cb8326..07e5a01d70 100644 --- a/src/main/java/redis/clients/jedis/UnifiedJedis.java +++ b/src/main/java/redis/clients/jedis/UnifiedJedis.java @@ -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)); } @@ -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)); } diff --git a/src/main/java/redis/clients/jedis/timeseries/RedisTimeSeriesCommands.java b/src/main/java/redis/clients/jedis/timeseries/RedisTimeSeriesCommands.java index 67c1b26fcf..513027c4cf 100644 --- a/src/main/java/redis/clients/jedis/timeseries/RedisTimeSeriesCommands.java +++ b/src/main/java/redis/clients/jedis/timeseries/RedisTimeSeriesCommands.java @@ -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); @@ -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} diff --git a/src/main/java/redis/clients/jedis/timeseries/RedisTimeSeriesPipelineCommands.java b/src/main/java/redis/clients/jedis/timeseries/RedisTimeSeriesPipelineCommands.java index b3304716dd..71b6e4c881 100644 --- a/src/main/java/redis/clients/jedis/timeseries/RedisTimeSeriesPipelineCommands.java +++ b/src/main/java/redis/clients/jedis/timeseries/RedisTimeSeriesPipelineCommands.java @@ -29,13 +29,13 @@ public interface RedisTimeSeriesPipelineCommands { Response tsIncrBy(String key, double value, long timestamp); - Response tsIncrBy(String key, double addend, TSIncrOrDecrByParams incrByParams); + Response tsIncrBy(String key, double addend, TSIncrByParams incrByParams); Response tsDecrBy(String key, double value); Response tsDecrBy(String key, double value, long timestamp); - Response tsDecrBy(String key, double subtrahend, TSIncrOrDecrByParams decrByParams); + Response tsDecrBy(String key, double subtrahend, TSDecrByParams decrByParams); Response> tsRange(String key, long fromTimestamp, long toTimestamp); diff --git a/src/main/java/redis/clients/jedis/timeseries/TSIncrOrDecrByParams.java b/src/main/java/redis/clients/jedis/timeseries/TSArithByParams.java similarity index 67% rename from src/main/java/redis/clients/jedis/timeseries/TSIncrOrDecrByParams.java rename to src/main/java/redis/clients/jedis/timeseries/TSArithByParams.java index fde848fb5a..1bc3df1c55 100644 --- a/src/main/java/redis/clients/jedis/timeseries/TSIncrOrDecrByParams.java +++ b/src/main/java/redis/clients/jedis/timeseries/TSArithByParams.java @@ -11,7 +11,7 @@ /** * Represents optional arguments of TS.INCRBY or TS.DECRBY commands. */ -public class TSIncrOrDecrByParams implements IParams { +class TSArithByParams> implements IParams { private Long timestamp; private Long retentionPeriod; @@ -25,51 +25,39 @@ public class TSIncrOrDecrByParams implements IParams { private Map 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; } /** @@ -78,9 +66,9 @@ public TSIncrOrDecrByParams ignore(long maxTimediff, double maxValDiff) { * @param labels label-value pairs * @return the object itself */ - public TSIncrOrDecrByParams labels(Map labels) { + public T labels(Map labels) { this.labels = labels; - return this; + return (T) this; } /** @@ -89,12 +77,12 @@ public TSIncrOrDecrByParams labels(Map 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 diff --git a/src/main/java/redis/clients/jedis/timeseries/TSDecrByParams.java b/src/main/java/redis/clients/jedis/timeseries/TSDecrByParams.java new file mode 100644 index 0000000000..afb776ad6b --- /dev/null +++ b/src/main/java/redis/clients/jedis/timeseries/TSDecrByParams.java @@ -0,0 +1,14 @@ +package redis.clients.jedis.timeseries; + +/** + * Represents optional arguments of TS.DECRBY command. + */ +public class TSDecrByParams extends TSArithByParams { + + public TSDecrByParams() { + } + + public static TSDecrByParams decrByParams() { + return new TSDecrByParams(); + } +} diff --git a/src/main/java/redis/clients/jedis/timeseries/TSIncrByParams.java b/src/main/java/redis/clients/jedis/timeseries/TSIncrByParams.java new file mode 100644 index 0000000000..db76a7ae26 --- /dev/null +++ b/src/main/java/redis/clients/jedis/timeseries/TSIncrByParams.java @@ -0,0 +1,14 @@ +package redis.clients.jedis.timeseries; + +/** + * Represents optional arguments of TS.INCRBY command. + */ +public class TSIncrByParams extends TSArithByParams { + + public TSIncrByParams() { + } + + public static TSIncrByParams incrByParams() { + return new TSIncrByParams(); + } +} 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 3f8eb66e7c..d4e47705e6 100644 --- a/src/test/java/redis/clients/jedis/modules/timeseries/TimeSeriesTest.java +++ b/src/test/java/redis/clients/jedis/modules/timeseries/TimeSeriesTest.java @@ -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))); }