-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Params * apply @gkorland's suggestion
- Loading branch information
Showing
5 changed files
with
335 additions
and
4 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
src/main/java/com/redislabs/redistimeseries/CreateParams.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,71 @@ | ||
package com.redislabs.redistimeseries; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import redis.clients.jedis.Protocol; | ||
import redis.clients.jedis.util.SafeEncoder; | ||
|
||
public class CreateParams { | ||
|
||
private Long retentionTime; | ||
private boolean uncompressed; | ||
private Long chunkSize; | ||
private DuplicatePolicy duplicatePolicy; | ||
private Map<String, String> labels; | ||
|
||
public static CreateParams createParams() { | ||
return new CreateParams(); | ||
} | ||
|
||
public CreateParams() {} | ||
|
||
public CreateParams retentionTime(long retentionTime) { | ||
this.retentionTime = retentionTime; | ||
return this; | ||
} | ||
|
||
public CreateParams uncompressed() { | ||
this.uncompressed = true; | ||
return this; | ||
} | ||
|
||
public CreateParams chunkSize(long chunkSize) { | ||
this.chunkSize = chunkSize; | ||
return this; | ||
} | ||
|
||
public CreateParams duplicatePolicy(DuplicatePolicy duplicatePolicy) { | ||
this.duplicatePolicy = duplicatePolicy; | ||
return this; | ||
} | ||
|
||
public CreateParams labels(Map<String, String> labels) { | ||
this.labels = labels; | ||
return this; | ||
} | ||
|
||
public void addOptionalParams(List<byte[]> params) { | ||
if (retentionTime != null) { | ||
params.add(Keyword.RETENTION.getRaw()); | ||
params.add(Protocol.toByteArray(retentionTime)); | ||
} | ||
if (uncompressed) { | ||
params.add(Keyword.UNCOMPRESSED.getRaw()); | ||
} | ||
if (chunkSize != null) { | ||
params.add(Keyword.CHUNK_SIZE.getRaw()); | ||
params.add(Protocol.toByteArray(chunkSize)); | ||
} | ||
if (duplicatePolicy != null) { | ||
params.add(Keyword.DUPLICATE_POLICY.getRaw()); | ||
params.add(duplicatePolicy.getRaw()); | ||
} | ||
if (labels != null) { | ||
params.add(Keyword.LABELS.getRaw()); | ||
for (Map.Entry<String, String> entry : labels.entrySet()) { | ||
params.add(SafeEncoder.encode(entry.getKey())); | ||
params.add(SafeEncoder.encode(entry.getValue())); | ||
} | ||
} | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
src/main/java/com/redislabs/redistimeseries/MultiRangeParams.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,71 @@ | ||
package com.redislabs.redistimeseries; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import redis.clients.jedis.Protocol; | ||
import redis.clients.jedis.util.SafeEncoder; | ||
|
||
public class MultiRangeParams { | ||
|
||
private Integer count; | ||
|
||
private Aggregation aggregationType; | ||
private long timeBucket; | ||
|
||
private boolean withLabels; | ||
|
||
public static MultiRangeParams multiRangeParams() { | ||
return new MultiRangeParams(); | ||
} | ||
|
||
public MultiRangeParams count(int count) { | ||
this.count = count; | ||
return this; | ||
} | ||
|
||
public MultiRangeParams aggregation(Aggregation aggregation, long timeBucket) { | ||
this.aggregationType = aggregation; | ||
this.timeBucket = timeBucket; | ||
return this; | ||
} | ||
|
||
public MultiRangeParams withLabels() { | ||
this.withLabels = true; | ||
return this; | ||
} | ||
|
||
public MultiRangeParams withLabels(boolean withLabels) { | ||
if (withLabels) { | ||
return withLabels(); | ||
} | ||
return this; | ||
} | ||
|
||
public byte[][] getByteParams(long from, long to, String... filters) { | ||
List<byte[]> params = new ArrayList<>(); | ||
params.add(Protocol.toByteArray(from)); | ||
params.add(Protocol.toByteArray(to)); | ||
|
||
if (count != null) { | ||
params.add(Keyword.COUNT.getRaw()); | ||
params.add(Protocol.toByteArray(count)); | ||
} | ||
|
||
if (aggregationType != null) { | ||
params.add(Keyword.AGGREGATION.getRaw()); | ||
params.add(aggregationType.getRaw()); | ||
params.add(Protocol.toByteArray(timeBucket)); | ||
} | ||
|
||
if (withLabels) { | ||
params.add(Keyword.WITHLABELS.getRaw()); | ||
} | ||
|
||
params.add(Keyword.FILTER.getRaw()); | ||
for (String filter : filters) { | ||
params.add(SafeEncoder.encode(filter)); | ||
} | ||
|
||
return params.toArray(new byte[params.size()][]); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/main/java/com/redislabs/redistimeseries/RangeParams.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,49 @@ | ||
package com.redislabs.redistimeseries; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import redis.clients.jedis.Protocol; | ||
import redis.clients.jedis.util.SafeEncoder; | ||
|
||
public class RangeParams { | ||
|
||
private Integer count; | ||
|
||
private Aggregation aggregationType; | ||
private long timeBucket; | ||
|
||
public static RangeParams rangeParams() { | ||
return new RangeParams(); | ||
} | ||
|
||
public RangeParams count(int count) { | ||
this.count = count; | ||
return this; | ||
} | ||
|
||
public RangeParams aggregation(Aggregation aggregation, long timeBucket) { | ||
this.aggregationType = aggregation; | ||
this.timeBucket = timeBucket; | ||
return this; | ||
} | ||
|
||
public byte[][] getByteParams(String key, long from, long to) { | ||
List<byte[]> params = new ArrayList<>(); | ||
params.add(SafeEncoder.encode(key)); | ||
params.add(Protocol.toByteArray(from)); | ||
params.add(Protocol.toByteArray(to)); | ||
|
||
if (count != null) { | ||
params.add(Keyword.COUNT.getRaw()); | ||
params.add(Protocol.toByteArray(count)); | ||
} | ||
|
||
if (aggregationType != null) { | ||
params.add(Keyword.AGGREGATION.getRaw()); | ||
params.add(aggregationType.getRaw()); | ||
params.add(Protocol.toByteArray(timeBucket)); | ||
} | ||
|
||
return params.toArray(new byte[params.size()][]); | ||
} | ||
} |
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
Oops, something went wrong.