-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support IGNORE and other optional arguments for timeseries commands (#…
…3860) * Re-implement TS.ADD command with optional arguments * Implement TS.INCRBY and TS.DECRBY commands with optional arguments * Support IGNORE argument for TS.[ CREATE | ALTER | ADD | INCRBY | DECRBY] commands --- * Cover optional arguments for timeseries commands - Re-implement TS.ADD command with optional arguments - Implement TS.INCRBY and TS.DECRBY commands with optional arguments * Introduce EncodingFormat enum for <COMPRESSED|UNCOMPRESSED> * Support IGNORE option and rename to TSIncrOrDecrByParams
- Loading branch information
Showing
14 changed files
with
600 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/main/java/redis/clients/jedis/timeseries/EncodingFormat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package redis.clients.jedis.timeseries; | ||
|
||
import redis.clients.jedis.args.Rawable; | ||
import redis.clients.jedis.util.SafeEncoder; | ||
|
||
/** | ||
* Specifies the series samples encoding format. | ||
*/ | ||
public enum EncodingFormat implements Rawable { | ||
|
||
COMPRESSED, | ||
UNCOMPRESSED; | ||
|
||
private final byte[] raw; | ||
|
||
private EncodingFormat() { | ||
raw = SafeEncoder.encode(name()); | ||
} | ||
|
||
@Override | ||
public byte[] getRaw() { | ||
return raw; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
src/main/java/redis/clients/jedis/timeseries/TSAddParams.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
package redis.clients.jedis.timeseries; | ||
|
||
import static redis.clients.jedis.Protocol.toByteArray; | ||
import static redis.clients.jedis.timeseries.TimeSeriesProtocol.TimeSeriesKeyword.*; | ||
|
||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
import redis.clients.jedis.CommandArguments; | ||
import redis.clients.jedis.params.IParams; | ||
|
||
/** | ||
* Represents optional arguments of TS.ADD command. | ||
*/ | ||
public class TSAddParams implements IParams { | ||
|
||
private Long retentionPeriod; | ||
private EncodingFormat encoding; | ||
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() { | ||
} | ||
|
||
public static TSAddParams addParams() { | ||
return new TSAddParams(); | ||
} | ||
|
||
public TSAddParams retention(long retentionPeriod) { | ||
this.retentionPeriod = retentionPeriod; | ||
return this; | ||
} | ||
|
||
public TSAddParams encoding(EncodingFormat encoding) { | ||
this.encoding = encoding; | ||
return this; | ||
} | ||
|
||
public TSAddParams chunkSize(long chunkSize) { | ||
this.chunkSize = chunkSize; | ||
return this; | ||
} | ||
|
||
public TSAddParams duplicatePolicy(DuplicatePolicy duplicatePolicy) { | ||
this.duplicatePolicy = duplicatePolicy; | ||
return this; | ||
} | ||
|
||
public TSAddParams onDuplicate(DuplicatePolicy onDuplicate) { | ||
this.onDuplicate = 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 | ||
* | ||
* @param labels label-value pairs | ||
* @return the object itself | ||
*/ | ||
public TSAddParams 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 TSAddParams label(String label, String value) { | ||
if (this.labels == null) { | ||
this.labels = new LinkedHashMap<>(); | ||
} | ||
this.labels.put(label, value); | ||
return this; | ||
} | ||
|
||
@Override | ||
public void addParams(CommandArguments args) { | ||
|
||
if (retentionPeriod != null) { | ||
args.add(RETENTION).add(toByteArray(retentionPeriod)); | ||
} | ||
|
||
if (encoding != null) { | ||
args.add(ENCODING).add(encoding); | ||
} | ||
|
||
if (chunkSize != null) { | ||
args.add(CHUNK_SIZE).add(toByteArray(chunkSize)); | ||
} | ||
|
||
if (duplicatePolicy != null) { | ||
args.add(DUPLICATE_POLICY).add(duplicatePolicy); | ||
} | ||
|
||
if (duplicatePolicy != null) { | ||
args.add(DUPLICATE_POLICY).add(duplicatePolicy); | ||
} | ||
|
||
if (onDuplicate != null) { | ||
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())); | ||
} | ||
} | ||
} |
Oops, something went wrong.