Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TimeSeries Commands & Tests #18

Merged
merged 2 commits into from
Aug 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/NRedisStack/ResponseParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public static IReadOnlyList<TimeSeriesLabel> ToLabelArray(RedisResult result)
return list;
}

public static IReadOnlyList<(string key, IReadOnlyList<TimeSeriesLabel> labels, TimeSeriesTuple value)> ParseMGetesponse(RedisResult result)
public static IReadOnlyList<(string key, IReadOnlyList<TimeSeriesLabel> labels, TimeSeriesTuple value)> ParseMGetResponse(RedisResult result)
{
RedisResult[] redisResults = (RedisResult[])result;
var list = new List<(string key, IReadOnlyList<TimeSeriesLabel> labels, TimeSeriesTuple values)>(redisResults.Length);
Expand Down Expand Up @@ -361,7 +361,7 @@ public static IReadOnlyList<TimeSeriesRule> ToRuleArray(RedisResult result)

compression = capacity = mergedNodes = unmergedNodes = totalCompressions = -1;
mergedWeight = unmergedWeight = -1.0;

RedisResult[] redisResults = ToArray(result);

for (int i = 0; i < redisResults.Length; ++i)
Expand Down Expand Up @@ -402,10 +402,10 @@ public static IReadOnlyList<TimeSeriesRule> ToRuleArray(RedisResult result)
public static TimeSeriesInformation ToTimeSeriesInfo(RedisResult result)
{
long totalSamples = -1, memoryUsage = -1, retentionTime = -1, chunkSize = -1, chunkCount = -1;
TimeStamp firstTimestamp = null, lastTimestamp = null;
IReadOnlyList<TimeSeriesLabel> labels = null;
IReadOnlyList<TimeSeriesRule> rules = null;
string sourceKey = null;
TimeStamp? firstTimestamp = null, lastTimestamp = null;
IReadOnlyList<TimeSeriesLabel>? labels = null;
IReadOnlyList<TimeSeriesRule>? rules = null;
string? sourceKey = null;
TsDuplicatePolicy? duplicatePolicy = null;
RedisResult[] redisResults = (RedisResult[])result;
for (int i = 0; i < redisResults.Length; ++i)
Expand Down Expand Up @@ -459,7 +459,7 @@ public static TimeSeriesInformation ToTimeSeriesInfo(RedisResult result)
lastTimestamp, retentionTime, chunkCount, chunkSize, labels, sourceKey, rules, duplicatePolicy);
}

public static IReadOnlyList<string>? ToStringArray(RedisResult result)
public static IReadOnlyList<string> ToStringArray(RedisResult result)
{
RedisResult[] redisResults = ToArray(result);

Expand Down
39 changes: 23 additions & 16 deletions src/NRedisStack/TimeSeries/TimeSeriesAux.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,11 @@ public static List<object> BuildTsCreateArgs(string key, long? retentionTime, IR
return args;
}

public static List<object> BuildTsAlterArgs(string key, long? retentionTime, IReadOnlyCollection<TimeSeriesLabel> labels)
public static List<object> BuildTsAlterArgs(string key, long? retentionTime, IReadOnlyCollection<TimeSeriesLabel>? labels)
{
var args = new List<object> {key};
args.AddRetentionTime(retentionTime);
args.AddLabels(labels);
if (labels != null) args.AddLabels(labels);
return args;
}

Expand All @@ -213,14 +213,14 @@ public static List<object> BuildTsAddArgs(string key, TimeStamp timestamp, doubl
return args;
}

public static List<object> BuildTsIncrDecrByArgs(string key, double value, TimeStamp timestamp, long? retentionTime,
IReadOnlyCollection<TimeSeriesLabel> labels, bool? uncompressed, long? chunkSizeBytes)
public static List<object> BuildTsIncrDecrByArgs(string key, double value, TimeStamp? timestamp, long? retentionTime,
IReadOnlyCollection<TimeSeriesLabel>? labels, bool? uncompressed, long? chunkSizeBytes)
{
var args = new List<object> {key, value};
args.AddTimeStamp(timestamp);
if (timestamp != null) args.AddTimeStamp(timestamp);
args.AddRetentionTime(retentionTime);
args.AddChunkSize(chunkSizeBytes);
args.AddLabels(labels);
if (labels != null) args.AddLabels(labels);
args.AddUncompressed(uncompressed);
return args;
}
Expand Down Expand Up @@ -252,33 +252,40 @@ public static List<object> BuildTsMgetArgs(IReadOnlyCollection<string> filter, b
return args;
}

public static List<object> BuildRangeArgs(string key, TimeStamp fromTimeStamp, TimeStamp toTimeStamp, long? count,
TsAggregation? aggregation, long? timeBucket, IReadOnlyCollection<TimeStamp> filterByTs, (long, long)? filterByValue,
TimeStamp align)
public static List<object> BuildRangeArgs(string key,
TimeStamp fromTimeStamp,
TimeStamp toTimeStamp,
long? count,
TsAggregation? aggregation,
long? timeBucket,
IReadOnlyCollection<TimeStamp>? filterByTs,
(long, long)? filterByValue,
TimeStamp? align)
{
var args = new List<object>()
{key, fromTimeStamp.Value, toTimeStamp.Value};
args.AddFilterByTs(filterByTs);

if (filterByTs != null) args.AddFilterByTs(filterByTs);
args.AddFilterByValue(filterByValue);
args.AddCount(count);
args.AddAlign(align);
if (align != null) args.AddAlign(align);
args.AddAggregation(aggregation, timeBucket);
return args;
}


public static List<object> BuildMultiRangeArgs(TimeStamp fromTimeStamp, TimeStamp toTimeStamp,
IReadOnlyCollection<string> filter, long? count, TsAggregation? aggregation, long? timeBucket,
bool? withLabels, (string, TsReduce)? groupbyTuple, IReadOnlyCollection<TimeStamp> filterByTs,
(long, long)? filterByValue, IReadOnlyCollection<string> selectLabels, TimeStamp align)
bool? withLabels, (string, TsReduce)? groupbyTuple, IReadOnlyCollection<TimeStamp>? filterByTs,
(long, long)? filterByValue, IReadOnlyCollection<string>? selectLabels, TimeStamp? align)
{
var args = new List<object>() {fromTimeStamp.Value, toTimeStamp.Value};
args.AddFilterByTs(filterByTs);
if (filterByTs != null) args.AddFilterByTs(filterByTs);
args.AddFilterByValue(filterByValue);
args.AddCount(count);
args.AddAlign(align);
if (align != null) args.AddAlign(align);
args.AddAggregation(aggregation, timeBucket);
args.AddWithLabels(withLabels, selectLabels);
if (selectLabels != null) args.AddWithLabels(withLabels, selectLabels);
args.AddFilters(filter);
args.AddGroupby(groupbyTuple);
return args;
Expand Down
Loading