Skip to content

Commit 0ae51b4

Browse files
authored
fix ts.create UNCOMPRESSED set to false explicitly (#329)
* fix ts.create UNCOMPRESSED set to false explicitly * fix format issue
1 parent 7bd65bc commit 0ae51b4

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

src/NRedisStack/TimeSeries/Literals/CommandArgs.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ internal class TimeSeriesArgs
55
public const string RETENTION = "RETENTION";
66
public const string LABELS = "LABELS";
77
public const string UNCOMPRESSED = "UNCOMPRESSED";
8+
public const string COMPRESSED = "COMPRESSED";
89
public const string COUNT = "COUNT";
910
public const string AGGREGATION = "AGGREGATION";
1011
public const string ALIGN = "ALIGN";

src/NRedisStack/TimeSeries/TimeSeriesParamsBuilder.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using NRedisStack.Literals;
22
using NRedisStack.Literals.Enums;
33
using NRedisStack.DataTypes;
4-
using System.Collections.ObjectModel;
54
using NRedisStack.Extensions;
65

76
namespace NRedisStack
@@ -29,7 +28,7 @@ public T AddRetentionTime(long retentionTime)
2928
this.retentionTime = retentionTime;
3029
return (T)this;
3130
}
32-
public T AddLabels(ReadOnlyCollection<TimeSeriesLabel> labels)
31+
public T AddLabels(IReadOnlyCollection<TimeSeriesLabel> labels)
3332
{
3433
this.labels = labels;
3534
return (T)this;
@@ -110,7 +109,7 @@ public static void AddUncompressed(this IList<object> args, bool? uncompressed)
110109
{
111110
if (uncompressed.HasValue)
112111
{
113-
args.Add(TimeSeriesArgs.UNCOMPRESSED);
112+
args.Add(uncompressed.Value ? TimeSeriesArgs.UNCOMPRESSED : TimeSeriesArgs.COMPRESSED);
114113
}
115114
}
116115

tests/NRedisStack.Tests/TimeSeries/TestAPI/TestCreate.cs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using NRedisStack.RedisStackCommands;
44
using NRedisStack.Literals.Enums;
55
using Xunit;
6-
using System.Runtime.CompilerServices;
76

87
namespace NRedisStack.Tests.TimeSeries.TestAPI
98
{
@@ -136,5 +135,33 @@ public void TestCreateAndIgnoreValues()
136135
Assert.Equal(11, (long)info[j + 1]);
137136
Assert.Equal(12, (long)info[k + 1]);
138137
}
138+
139+
[Fact]
140+
public void TestParamsBuilder()
141+
{
142+
TsCreateParams parameters = new TsCreateParamsBuilder()
143+
.AddChunkSizeBytes(1000)
144+
.AddDuplicatePolicy(TsDuplicatePolicy.FIRST)
145+
.AddIgnoreValues(11, 12)
146+
.AddLabels(new List<TimeSeriesLabel>() { new TimeSeriesLabel("key", "value") })
147+
.AddRetentionTime(5000)
148+
.AddUncompressed(true).build();
149+
150+
var command = TimeSeriesCommandsBuilder.Create(key, parameters);
151+
var expectedArgs = new object[] { key, "RETENTION", 5000L, "CHUNK_SIZE", 1000L, "LABELS", "key", "value", "UNCOMPRESSED", "DUPLICATE_POLICY", "FIRST", "IGNORE", 11L, 12L };
152+
Assert.Equal(expectedArgs, command.Args);
153+
154+
parameters = new TsCreateParamsBuilder()
155+
.AddChunkSizeBytes(1000)
156+
.AddDuplicatePolicy(TsDuplicatePolicy.FIRST)
157+
.AddIgnoreValues(11, 12)
158+
.AddLabels(new List<TimeSeriesLabel>() { new TimeSeriesLabel("key", "value") })
159+
.AddRetentionTime(5000)
160+
.AddUncompressed(false).build();
161+
162+
command = TimeSeriesCommandsBuilder.Create(key, parameters);
163+
expectedArgs = new object[] { key, "RETENTION", 5000L, "CHUNK_SIZE", 1000L, "LABELS", "key", "value", "COMPRESSED", "DUPLICATE_POLICY", "FIRST", "IGNORE", 11L, 12L };
164+
Assert.Equal(expectedArgs, command.Args);
165+
}
139166
}
140167
}

0 commit comments

Comments
 (0)