diff --git a/src/NRedisStack/TimeSeries/Literals/CommandArgs.cs b/src/NRedisStack/TimeSeries/Literals/CommandArgs.cs index 2c7df31c..0bdd7812 100644 --- a/src/NRedisStack/TimeSeries/Literals/CommandArgs.cs +++ b/src/NRedisStack/TimeSeries/Literals/CommandArgs.cs @@ -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"; diff --git a/src/NRedisStack/TimeSeries/TimeSeriesParamsBuilder.cs b/src/NRedisStack/TimeSeries/TimeSeriesParamsBuilder.cs index c9345d04..0adf08d6 100644 --- a/src/NRedisStack/TimeSeries/TimeSeriesParamsBuilder.cs +++ b/src/NRedisStack/TimeSeries/TimeSeriesParamsBuilder.cs @@ -1,7 +1,6 @@ using NRedisStack.Literals; using NRedisStack.Literals.Enums; using NRedisStack.DataTypes; -using System.Collections.ObjectModel; using NRedisStack.Extensions; namespace NRedisStack @@ -29,7 +28,7 @@ public T AddRetentionTime(long retentionTime) this.retentionTime = retentionTime; return (T)this; } - public T AddLabels(ReadOnlyCollection labels) + public T AddLabels(IReadOnlyCollection labels) { this.labels = labels; return (T)this; @@ -110,7 +109,7 @@ public static void AddUncompressed(this IList args, bool? uncompressed) { if (uncompressed.HasValue) { - args.Add(TimeSeriesArgs.UNCOMPRESSED); + args.Add(uncompressed.Value ? TimeSeriesArgs.UNCOMPRESSED : TimeSeriesArgs.COMPRESSED); } } diff --git a/tests/NRedisStack.Tests/TimeSeries/TestAPI/TestCreate.cs b/tests/NRedisStack.Tests/TimeSeries/TestAPI/TestCreate.cs index 69a9c263..26185c58 100644 --- a/tests/NRedisStack.Tests/TimeSeries/TestAPI/TestCreate.cs +++ b/tests/NRedisStack.Tests/TimeSeries/TestAPI/TestCreate.cs @@ -3,7 +3,6 @@ using NRedisStack.RedisStackCommands; using NRedisStack.Literals.Enums; using Xunit; -using System.Runtime.CompilerServices; namespace NRedisStack.Tests.TimeSeries.TestAPI { @@ -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() { 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() { 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); + } } }