Skip to content

Commit cbdf537

Browse files
shacharPashslorello89chayim
authored
Target .NET Standard 2.0 (#89)
* Target .NET Standard 2.0 * add condition * update to the latest version of System.Text.Json * adjustments to run in .NET Framework, adding job to run tests for .NET Framework * adjustments to run in .NET Framework, adding job to run tests for .NET Framework (#91) * syntax fix * trying to manually switch to linux containers * trying other format * fixing syntax * swapping flags * nixing windows job * try dropping framework restrictions * dropping 462 * trying to test on windows using WSL 2 * adding curl install * also installing gpg. . . * and lsb-release... * trying to log start * switching to ubuntu * change test name * delete distribution: Ubuntu-20.04 line * experiment * trying with direct tar download * ok let's actually add it this time * resetting as a jammy instance, adding a ls for debugging * removing mv * removing process spinoff * fixing syntax * libgomp1? * spin off again * trying a new tact for spinning off process * old school spin off? * renaming * versioning * newline * PS variable access * reverting * other means of seeding env vars? * add sleep to HSETandSearch test * add sleep to TestQueryCommandBuilderScore Test * conditional framework usage based on platform --------- Co-authored-by: slorello89 <slorello89@gmail.com> Co-authored-by: Steve Lorello <42971704+slorello89@users.noreply.github.com> Co-authored-by: Chayim I. Kirshen <c@kirshen.com> Co-authored-by: slorello89 <steve.lorello@redis.com>
1 parent df68194 commit cbdf537

File tree

13 files changed

+78
-26
lines changed

13 files changed

+78
-26
lines changed

.github/workflows/integration.yml

+29-5
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@ on:
1212
- cron: "0 1 * * *"
1313

1414
env:
15-
redis_stack_version: 6.2.2-v5
15+
redis_stack_version: 6.2.6-v6
1616

1717
jobs:
18-
19-
build_and_test:
18+
build_and_Test:
2019
name: Build and test
2120
runs-on: ubuntu-latest
2221
steps:
@@ -36,12 +35,37 @@ jobs:
3635
- name: Build
3736
run: dotnet build --no-restore /p:ContinuousIntegrationBuild=true
3837
- name: Test
39-
run: dotnet test --no-build --verbosity normal /p:CollectCoverage=true /p:CoverletOutputFormat=opencover
38+
run: dotnet test -f net6.0 --no-build --verbosity normal /p:CollectCoverage=true /p:CoverletOutputFormat=opencover
39+
- name: Test
40+
run: dotnet test -f net7.0 --no-build --verbosity normal /p:CollectCoverage=true /p:CoverletOutputFormat=opencover
4041
- name: Codecov
4142
uses: codecov/codecov-action@v3
4243
with:
4344
token: ${{secrets.CODECOV_TOKEN}}
4445
verbose: true
45-
4646
- name: Build
4747
run: dotnet pack -c Release
48+
build_and_test_windows:
49+
name: Build and Test on Windows
50+
runs-on: windows-latest
51+
steps:
52+
- uses: actions/checkout@v3
53+
- uses: Vampire/setup-wsl@v2
54+
with:
55+
distribution: Ubuntu-22.04
56+
- name: Install Redis
57+
shell: wsl-bash {0}
58+
run: |
59+
sudo apt-get update
60+
sudo apt-get install curl -y && sudo apt-get install gpg -y && apt-get install lsb-release -y && apt-get install libgomp1 -y
61+
curl https://packages.redis.io/redis-stack/redis-stack-server-${{env.redis_stack_version}}.jammy.x86_64.tar.gz -o redis-stack.tar.gz
62+
tar xf redis-stack.tar.gz
63+
- name: Restore dependencies
64+
run: dotnet restore
65+
- name: Build
66+
run: dotnet build --no-restore /p:ContinuousIntegrationBuild=true
67+
- name: Test
68+
shell: cmd
69+
run: |
70+
START wsl ./redis-stack-server-${{env.redis_stack_version}}/bin/redis-stack-server &
71+
dotnet test -f net481 --no-build --verbosity normal

src/NRedisStack/Graph/Header.cs

+10-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ internal Header(RedisResult result)
3434
SchemaTypes = new List<ResultSetColumnTypes>();
3535
SchemaNames = new List<string>();
3636

37-
foreach(RedisResult[] tuple in (RedisResult[])result)
37+
foreach (RedisResult[] tuple in (RedisResult[])result)
3838
{
3939
SchemaTypes.Add((ResultSetColumnTypes)(int)tuple[0]);
4040
SchemaNames.Add((string)tuple[1]);
@@ -63,9 +63,17 @@ public override bool Equals(object? obj)
6363

6464
public override int GetHashCode()
6565
{
66-
return HashCode.Combine(SchemaTypes, SchemaNames);
66+
unchecked
67+
{
68+
int hash = 17;
69+
hash = hash * 23 + SchemaTypes.GetHashCode();
70+
hash = hash * 23 + SchemaNames.GetHashCode();
71+
return hash;
72+
}
6773
}
6874

75+
76+
6977
public override string ToString() =>
7078
$"Header{{schemaTypes=[{string.Join(", ", SchemaTypes)}], schemaNames=[{string.Join(", ", SchemaNames)}]}}";
7179
}

src/NRedisStack/Json/JsonCommands.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ public bool Set(RedisKey key, RedisValue path, RedisValue json, When when = When
4242
/// <inheritdoc/>
4343
public bool SetFromFile(RedisKey key, RedisValue path, string filePath, When when = When.Always)
4444
{
45-
if(!File.Exists(filePath))
45+
if (!File.Exists(filePath))
4646
{
4747
throw new FileNotFoundException($"File {filePath} not found.");
4848
}
4949

50-
string fileContent = File.ReadAllText(filePath);
50+
string fileContent = File.ReadAllText(filePath);
5151
return Set(key, path, fileContent, when);
5252
}
5353

@@ -60,7 +60,7 @@ public int SetFromDirectory(RedisValue path, string filesPath, When when = When.
6060
foreach (var filePath in files)
6161
{
6262
key = filePath.Substring(0, filePath.IndexOf("."));
63-
if(SetFromFile(key, path, filePath, when))
63+
if (SetFromFile(key, path, filePath, when))
6464
{
6565
inserted++;
6666
}
@@ -111,12 +111,12 @@ public JsonType[] Type(RedisKey key, string? path = null)
111111

112112
if (result.Type == ResultType.MultiBulk)
113113
{
114-
return ((RedisResult[])result!).Select(x => Enum.Parse<JsonType>(x.ToString()!.ToUpper())).ToArray();
114+
return ((RedisResult[])result!).Select(x => (JsonType)Enum.Parse(typeof(JsonType), x.ToString()!.ToUpper())).ToArray();
115115
}
116116

117117
if (result.Type == ResultType.BulkString)
118118
{
119-
return new[] { Enum.Parse<JsonType>(result.ToString()!.ToUpper()) };
119+
return new[] { (JsonType)Enum.Parse(typeof(JsonType), result.ToString()!.ToUpper()) };
120120
}
121121

122122
return Array.Empty<JsonType>();

src/NRedisStack/Json/JsonCommandsAsync.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,12 @@ public async Task<JsonType[]> TypeAsync(RedisKey key, string? path = null)
209209

210210
if (result.Type == ResultType.MultiBulk)
211211
{
212-
return ((RedisResult[])result!).Select(x => Enum.Parse<JsonType>(x.ToString()!.ToUpper())).ToArray();
212+
return ((RedisResult[])result!).Select(x => (JsonType)Enum.Parse(typeof(JsonType), x.ToString()!.ToUpper())).ToArray();
213213
}
214214

215215
if (result.Type == ResultType.BulkString)
216216
{
217-
return new[] { Enum.Parse<JsonType>(result.ToString()!.ToUpper()) };
217+
return new[] { (JsonType)Enum.Parse(typeof(JsonType), result.ToString()!.ToUpper()) };
218218
}
219219

220220
return Array.Empty<JsonType>();

src/NRedisStack/NRedisStack.csproj

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
5-
<ImplicitUsings>enable</ImplicitUsings>
6-
<Nullable>enable</Nullable>
4+
<Nullable>enable</Nullable>
5+
<TargetFrameworks>netstandard2.0;net6.0;net7.0</TargetFrameworks>
6+
<LangVersion>latest</LangVersion>
7+
<ImplicitUsings>enable</ImplicitUsings>
78
<Authors>Redis Open Source</Authors>
89
<Owners>Redis OSS</Owners>
910
<Description>.Net Client for Redis Stack</Description>
@@ -14,6 +15,7 @@
1415
</PropertyGroup>
1516

1617
<ItemGroup>
18+
<PackageReference Include="System.Text.Json" Version="7.0.2" Condition="'$(TargetFramework)' == 'netstandard2.0'" />
1719
<PackageReference Include="StackExchange.Redis" Version="2.6.90" />
1820
<None Include="..\..\README.md" Pack="true" PackagePath="\" />
1921
</ItemGroup>

src/NRedisStack/ResponseParser.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public static long ToLong(this RedisResult result)
4747

4848
public static double ToDouble(this RedisResult result)
4949
{
50+
if (result.ToString() == "nan")
51+
return double.NaN;
5052
if ((double?)result == null)
5153
throw new ArgumentNullException(nameof(result));
5254
return (double)result;
@@ -591,7 +593,7 @@ public static IEnumerable<HashSet<string>> ToHashSets(this RedisResult result)
591593
if (res.All(x => x.Type != ResultType.MultiBulk))
592594
{
593595
var keys = res.Select(x => x.ToString()!);
594-
sets.Add(keys.ToHashSet());
596+
sets.Add(new HashSet<string>(keys));
595597
return sets;
596598
}
597599

src/NRedisStack/Tdigest/TdigestCommands.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ public double Max(RedisKey key)
4444
/// <inheritdoc/>
4545
public double Min(RedisKey key)
4646
{
47-
return _db.Execute(TdigestCommandBuilder.Min(key)).ToDouble();
47+
var cmd = TdigestCommandBuilder.Min(key);
48+
var res =_db.Execute(cmd);
49+
return res.ToDouble();
4850
}
4951

5052
/// <inheritdoc/>

tests/NRedisStack.Tests/Examples/ExamplesTests.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ public void HSETandSearch()
4646
// Create the index
4747
ft.Create("example_index", parameters, schema);
4848

49+
//sleep:
50+
System.Threading.Thread.Sleep(2000);
51+
4952
// Search all hashes in the index
5053
var noFilters = ft.Search("example_index", new Query());
5154
// noFilters now contains: student:1111, student:5555, pupil:4444, student:3333
@@ -61,7 +64,7 @@ public void HSETandSearch()
6164
// Search for hashes with last name of Rod
6265
var lastNameRod = ft.Search("example_index", new Query("@last:Rod"));
6366
// lastNameRod is empty because there are no hashes with a last name of Rod that match the index definition
64-
// Assert.Equal(4, noFilters.TotalResults); TODO: checl why this fails in the CI sometimes
67+
Assert.Equal(4, noFilters.TotalResults);
6568
Assert.Equal(2, startWithJo.TotalResults);
6669
Assert.Equal(1, namedPat.TotalResults);
6770
Assert.Equal(0, lastNameRod.TotalResults);

tests/NRedisStack.Tests/NRedisStack.Tests.csproj

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
32
<PropertyGroup>
4-
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
3+
<IsWindows>$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::get_Windows())))</IsWindows>
4+
<TargetFrameworks Condition=" '$(IsWindows)' == 'true'">net6.0;net7.0;net481</TargetFrameworks>
5+
<TargetFrameworks Condition=" '$(IsWindows)' != 'true'">net6.0;net7.0</TargetFrameworks>
56
<ImplicitUsings>enable</ImplicitUsings>
67
<Nullable>enable</Nullable>
8+
<LangVersion>latest</LangVersion>
79

810
<IsPackable>false</IsPackable>
911
</PropertyGroup>

tests/NRedisStack.Tests/Search/SearchTests.cs

+3
Original file line numberDiff line numberDiff line change
@@ -1755,6 +1755,9 @@ public void TestQueryCommandBuilderScore()
17551755

17561756
db.Execute("JSON.SET", "doc:1", "$", "[{\"arr\": [1, 2, 3]}, {\"val\": \"hello\"}, {\"val\": \"world\"}]");
17571757
db.Execute("FT.CREATE", "idx", "ON", "JSON", "PREFIX", "1", "doc:", "SCHEMA", "$..arr", "AS", "arr", "NUMERIC", "$..val", "AS", "val", "TEXT");
1758+
// sleep:
1759+
Thread.Sleep(2000);
1760+
17581761
var res = ft.Search("idx", new Query("*").ReturnFields("arr", "val").SetWithScores().SetPayload("arr"));
17591762
Assert.Equal(1, res.TotalResults);
17601763
}

tests/NRedisStack.Tests/Tdigest/TdigestTests.cs

+6-2
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ static Tuple<double, long> RandomValueWeight()
666666
{
667667
Random random = new Random();
668668

669-
return new Tuple<double, long>(random.NextDouble() * 10000, random.NextInt64() + 1);
669+
return new Tuple<double, long>(random.NextDouble() * 10000, random.Next() + 1);
670670
}
671671

672672
static Tuple<double, long>[] RandomValueWeightArray(int count)
@@ -687,7 +687,11 @@ static Tuple<double, long> DefinedValueWeight(double value, long weight)
687687
private static double[] WeightedValue(double value, int weight)
688688
{
689689
double[] values = new double[weight];
690-
Array.Fill(values, value);
690+
for (var i = 0; i < values.Length; i++)
691+
{
692+
values[i] = value;
693+
}
694+
691695
return values;
692696
}
693697
}

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using NRedisStack.DataTypes;
2+
using NRedisStack.Literals.Enums;
23
using NRedisStack.RedisStackCommands;
34
using StackExchange.Redis;
45
using Xunit;
@@ -88,7 +89,7 @@ public void TestOverrideMADD()
8889

8990
foreach (string key in keys)
9091
{
91-
ts.Create(key);
92+
ts.Create(key, duplicatePolicy: TsDuplicatePolicy.MAX);
9293
}
9394

9495
List<DateTime> oldTimeStamps = new List<DateTime>();

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using NRedisStack.DataTypes;
2+
using NRedisStack.Literals.Enums;
23
using NRedisStack.RedisStackCommands;
34
using StackExchange.Redis;
45
using Xunit;
@@ -82,7 +83,7 @@ public async Task TestOverrideMAdd()
8283

8384
foreach (var key in keys)
8485
{
85-
await ts.CreateAsync(key);
86+
await ts.CreateAsync(key, duplicatePolicy: TsDuplicatePolicy.MAX);
8687
}
8788

8889
var oldTimeStamps = new List<DateTime>();

0 commit comments

Comments
 (0)