Skip to content
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
1 change: 1 addition & 0 deletions src/NRedisStack/TimeSeries/Literals/CommandArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ internal class TimeSeriesArgs
public const string RETENTION = "RETENTION";
public const string LABELS = "LABELS";
public const string UNCOMPRESSED = "UNCOMPRESSED";
public const string COMPRESSED = "COMPRESSED";
public const string COUNT = "COUNT";
public const string AGGREGATION = "AGGREGATION";
public const string ALIGN = "ALIGN";
Expand Down
5 changes: 2 additions & 3 deletions src/NRedisStack/TimeSeries/TimeSeriesParamsBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using NRedisStack.Literals;
using NRedisStack.Literals.Enums;
using NRedisStack.DataTypes;
using System.Collections.ObjectModel;
using NRedisStack.Extensions;

namespace NRedisStack
Expand Down Expand Up @@ -29,7 +28,7 @@ public T AddRetentionTime(long retentionTime)
this.retentionTime = retentionTime;
return (T)this;
}
public T AddLabels(ReadOnlyCollection<TimeSeriesLabel> labels)
public T AddLabels(IReadOnlyCollection<TimeSeriesLabel> labels)
{
this.labels = labels;
return (T)this;
Expand Down Expand Up @@ -110,7 +109,7 @@ public static void AddUncompressed(this IList<object> args, bool? uncompressed)
{
if (uncompressed.HasValue)
{
args.Add(TimeSeriesArgs.UNCOMPRESSED);
args.Add(uncompressed.Value ? TimeSeriesArgs.UNCOMPRESSED : TimeSeriesArgs.COMPRESSED);
}
}

Expand Down
29 changes: 28 additions & 1 deletion tests/NRedisStack.Tests/TimeSeries/TestAPI/TestCreate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using NRedisStack.RedisStackCommands;
using NRedisStack.Literals.Enums;
using Xunit;
using System.Runtime.CompilerServices;

namespace NRedisStack.Tests.TimeSeries.TestAPI
{
Expand Down Expand Up @@ -136,5 +135,33 @@ public void TestCreateAndIgnoreValues()
Assert.Equal(11, (long)info[j + 1]);
Assert.Equal(12, (long)info[k + 1]);
}

[Fact]
public void TestParamsBuilder()
{
TsCreateParams parameters = new TsCreateParamsBuilder()
.AddChunkSizeBytes(1000)
.AddDuplicatePolicy(TsDuplicatePolicy.FIRST)
.AddIgnoreValues(11, 12)
.AddLabels(new List<TimeSeriesLabel>() { new TimeSeriesLabel("key", "value") })
.AddRetentionTime(5000)
.AddUncompressed(true).build();

var command = TimeSeriesCommandsBuilder.Create(key, parameters);
var expectedArgs = new object[] { key, "RETENTION", 5000L, "CHUNK_SIZE", 1000L, "LABELS", "key", "value", "UNCOMPRESSED", "DUPLICATE_POLICY", "FIRST", "IGNORE", 11L, 12L };
Assert.Equal(expectedArgs, command.Args);

parameters = new TsCreateParamsBuilder()
.AddChunkSizeBytes(1000)
.AddDuplicatePolicy(TsDuplicatePolicy.FIRST)
.AddIgnoreValues(11, 12)
.AddLabels(new List<TimeSeriesLabel>() { new TimeSeriesLabel("key", "value") })
.AddRetentionTime(5000)
.AddUncompressed(false).build();

command = TimeSeriesCommandsBuilder.Create(key, parameters);
expectedArgs = new object[] { key, "RETENTION", 5000L, "CHUNK_SIZE", 1000L, "LABELS", "key", "value", "COMPRESSED", "DUPLICATE_POLICY", "FIRST", "IGNORE", 11L, 12L };
Assert.Equal(expectedArgs, command.Args);
}
}
}