diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 4d0ddcf9..a3e3b094 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -12,11 +12,10 @@ on: - cron: "0 1 * * *" env: - redis_stack_version: 6.2.2-v5 + redis_stack_version: 6.2.6-v6 jobs: - - build_and_test: + build_and_Test: name: Build and test runs-on: ubuntu-latest steps: @@ -36,12 +35,37 @@ jobs: - name: Build run: dotnet build --no-restore /p:ContinuousIntegrationBuild=true - name: Test - run: dotnet test --no-build --verbosity normal /p:CollectCoverage=true /p:CoverletOutputFormat=opencover + run: dotnet test -f net6.0 --no-build --verbosity normal /p:CollectCoverage=true /p:CoverletOutputFormat=opencover + - name: Test + run: dotnet test -f net7.0 --no-build --verbosity normal /p:CollectCoverage=true /p:CoverletOutputFormat=opencover - name: Codecov uses: codecov/codecov-action@v3 with: token: ${{secrets.CODECOV_TOKEN}} verbose: true - - name: Build run: dotnet pack -c Release + build_and_test_windows: + name: Build and Test on Windows + runs-on: windows-latest + steps: + - uses: actions/checkout@v3 + - uses: Vampire/setup-wsl@v2 + with: + distribution: Ubuntu-22.04 + - name: Install Redis + shell: wsl-bash {0} + run: | + sudo apt-get update + sudo apt-get install curl -y && sudo apt-get install gpg -y && apt-get install lsb-release -y && apt-get install libgomp1 -y + curl https://packages.redis.io/redis-stack/redis-stack-server-${{env.redis_stack_version}}.jammy.x86_64.tar.gz -o redis-stack.tar.gz + tar xf redis-stack.tar.gz + - name: Restore dependencies + run: dotnet restore + - name: Build + run: dotnet build --no-restore /p:ContinuousIntegrationBuild=true + - name: Test + shell: cmd + run: | + START wsl ./redis-stack-server-${{env.redis_stack_version}}/bin/redis-stack-server & + dotnet test -f net481 --no-build --verbosity normal diff --git a/src/NRedisStack/Graph/Header.cs b/src/NRedisStack/Graph/Header.cs index 3101986c..26f0bf5c 100644 --- a/src/NRedisStack/Graph/Header.cs +++ b/src/NRedisStack/Graph/Header.cs @@ -34,7 +34,7 @@ internal Header(RedisResult result) SchemaTypes = new List(); SchemaNames = new List(); - foreach(RedisResult[] tuple in (RedisResult[])result) + foreach (RedisResult[] tuple in (RedisResult[])result) { SchemaTypes.Add((ResultSetColumnTypes)(int)tuple[0]); SchemaNames.Add((string)tuple[1]); @@ -63,9 +63,17 @@ public override bool Equals(object? obj) public override int GetHashCode() { - return HashCode.Combine(SchemaTypes, SchemaNames); + unchecked + { + int hash = 17; + hash = hash * 23 + SchemaTypes.GetHashCode(); + hash = hash * 23 + SchemaNames.GetHashCode(); + return hash; + } } + + public override string ToString() => $"Header{{schemaTypes=[{string.Join(", ", SchemaTypes)}], schemaNames=[{string.Join(", ", SchemaNames)}]}}"; } diff --git a/src/NRedisStack/Json/JsonCommands.cs b/src/NRedisStack/Json/JsonCommands.cs index 6e309be2..0add4087 100644 --- a/src/NRedisStack/Json/JsonCommands.cs +++ b/src/NRedisStack/Json/JsonCommands.cs @@ -42,12 +42,12 @@ public bool Set(RedisKey key, RedisValue path, RedisValue json, When when = When /// public bool SetFromFile(RedisKey key, RedisValue path, string filePath, When when = When.Always) { - if(!File.Exists(filePath)) + if (!File.Exists(filePath)) { throw new FileNotFoundException($"File {filePath} not found."); } - string fileContent = File.ReadAllText(filePath); + string fileContent = File.ReadAllText(filePath); return Set(key, path, fileContent, when); } @@ -60,7 +60,7 @@ public int SetFromDirectory(RedisValue path, string filesPath, When when = When. foreach (var filePath in files) { key = filePath.Substring(0, filePath.IndexOf(".")); - if(SetFromFile(key, path, filePath, when)) + if (SetFromFile(key, path, filePath, when)) { inserted++; } @@ -111,12 +111,12 @@ public JsonType[] Type(RedisKey key, string? path = null) if (result.Type == ResultType.MultiBulk) { - return ((RedisResult[])result!).Select(x => Enum.Parse(x.ToString()!.ToUpper())).ToArray(); + return ((RedisResult[])result!).Select(x => (JsonType)Enum.Parse(typeof(JsonType), x.ToString()!.ToUpper())).ToArray(); } if (result.Type == ResultType.BulkString) { - return new[] { Enum.Parse(result.ToString()!.ToUpper()) }; + return new[] { (JsonType)Enum.Parse(typeof(JsonType), result.ToString()!.ToUpper()) }; } return Array.Empty(); diff --git a/src/NRedisStack/Json/JsonCommandsAsync.cs b/src/NRedisStack/Json/JsonCommandsAsync.cs index d20c993c..12d0e5fc 100644 --- a/src/NRedisStack/Json/JsonCommandsAsync.cs +++ b/src/NRedisStack/Json/JsonCommandsAsync.cs @@ -209,12 +209,12 @@ public async Task TypeAsync(RedisKey key, string? path = null) if (result.Type == ResultType.MultiBulk) { - return ((RedisResult[])result!).Select(x => Enum.Parse(x.ToString()!.ToUpper())).ToArray(); + return ((RedisResult[])result!).Select(x => (JsonType)Enum.Parse(typeof(JsonType), x.ToString()!.ToUpper())).ToArray(); } if (result.Type == ResultType.BulkString) { - return new[] { Enum.Parse(result.ToString()!.ToUpper()) }; + return new[] { (JsonType)Enum.Parse(typeof(JsonType), result.ToString()!.ToUpper()) }; } return Array.Empty(); diff --git a/src/NRedisStack/NRedisStack.csproj b/src/NRedisStack/NRedisStack.csproj index ed1e5667..d993c79e 100644 --- a/src/NRedisStack/NRedisStack.csproj +++ b/src/NRedisStack/NRedisStack.csproj @@ -1,9 +1,10 @@ - net6.0;net7.0 - enable - enable + enable + netstandard2.0;net6.0;net7.0 + latest + enable Redis Open Source Redis OSS .Net Client for Redis Stack @@ -14,6 +15,7 @@ + diff --git a/src/NRedisStack/ResponseParser.cs b/src/NRedisStack/ResponseParser.cs index da2fc361..a8b0fd85 100644 --- a/src/NRedisStack/ResponseParser.cs +++ b/src/NRedisStack/ResponseParser.cs @@ -47,6 +47,8 @@ public static long ToLong(this RedisResult result) public static double ToDouble(this RedisResult result) { + if (result.ToString() == "nan") + return double.NaN; if ((double?)result == null) throw new ArgumentNullException(nameof(result)); return (double)result; @@ -591,7 +593,7 @@ public static IEnumerable> ToHashSets(this RedisResult result) if (res.All(x => x.Type != ResultType.MultiBulk)) { var keys = res.Select(x => x.ToString()!); - sets.Add(keys.ToHashSet()); + sets.Add(new HashSet(keys)); return sets; } diff --git a/src/NRedisStack/Tdigest/TdigestCommands.cs b/src/NRedisStack/Tdigest/TdigestCommands.cs index 9ee9fd56..72d5f847 100644 --- a/src/NRedisStack/Tdigest/TdigestCommands.cs +++ b/src/NRedisStack/Tdigest/TdigestCommands.cs @@ -44,7 +44,9 @@ public double Max(RedisKey key) /// public double Min(RedisKey key) { - return _db.Execute(TdigestCommandBuilder.Min(key)).ToDouble(); + var cmd = TdigestCommandBuilder.Min(key); + var res =_db.Execute(cmd); + return res.ToDouble(); } /// diff --git a/tests/NRedisStack.Tests/Examples/ExamplesTests.cs b/tests/NRedisStack.Tests/Examples/ExamplesTests.cs index d9428516..5e69078b 100644 --- a/tests/NRedisStack.Tests/Examples/ExamplesTests.cs +++ b/tests/NRedisStack.Tests/Examples/ExamplesTests.cs @@ -46,6 +46,9 @@ public void HSETandSearch() // Create the index ft.Create("example_index", parameters, schema); + //sleep: + System.Threading.Thread.Sleep(2000); + // Search all hashes in the index var noFilters = ft.Search("example_index", new Query()); // noFilters now contains: student:1111, student:5555, pupil:4444, student:3333 @@ -61,7 +64,7 @@ public void HSETandSearch() // Search for hashes with last name of Rod var lastNameRod = ft.Search("example_index", new Query("@last:Rod")); // lastNameRod is empty because there are no hashes with a last name of Rod that match the index definition - // Assert.Equal(4, noFilters.TotalResults); TODO: checl why this fails in the CI sometimes + Assert.Equal(4, noFilters.TotalResults); Assert.Equal(2, startWithJo.TotalResults); Assert.Equal(1, namedPat.TotalResults); Assert.Equal(0, lastNameRod.TotalResults); diff --git a/tests/NRedisStack.Tests/NRedisStack.Tests.csproj b/tests/NRedisStack.Tests/NRedisStack.Tests.csproj index 01c824f8..a11d6366 100644 --- a/tests/NRedisStack.Tests/NRedisStack.Tests.csproj +++ b/tests/NRedisStack.Tests/NRedisStack.Tests.csproj @@ -1,9 +1,11 @@ - - net6.0;net7.0 + $([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::get_Windows()))) + net6.0;net7.0;net481 + net6.0;net7.0 enable enable + latest false diff --git a/tests/NRedisStack.Tests/Search/SearchTests.cs b/tests/NRedisStack.Tests/Search/SearchTests.cs index 19e01990..d89b1f48 100644 --- a/tests/NRedisStack.Tests/Search/SearchTests.cs +++ b/tests/NRedisStack.Tests/Search/SearchTests.cs @@ -1755,6 +1755,9 @@ public void TestQueryCommandBuilderScore() db.Execute("JSON.SET", "doc:1", "$", "[{\"arr\": [1, 2, 3]}, {\"val\": \"hello\"}, {\"val\": \"world\"}]"); db.Execute("FT.CREATE", "idx", "ON", "JSON", "PREFIX", "1", "doc:", "SCHEMA", "$..arr", "AS", "arr", "NUMERIC", "$..val", "AS", "val", "TEXT"); + // sleep: + Thread.Sleep(2000); + var res = ft.Search("idx", new Query("*").ReturnFields("arr", "val").SetWithScores().SetPayload("arr")); Assert.Equal(1, res.TotalResults); } diff --git a/tests/NRedisStack.Tests/Tdigest/TdigestTests.cs b/tests/NRedisStack.Tests/Tdigest/TdigestTests.cs index eb8d43a1..c1592a66 100644 --- a/tests/NRedisStack.Tests/Tdigest/TdigestTests.cs +++ b/tests/NRedisStack.Tests/Tdigest/TdigestTests.cs @@ -666,7 +666,7 @@ static Tuple RandomValueWeight() { Random random = new Random(); - return new Tuple(random.NextDouble() * 10000, random.NextInt64() + 1); + return new Tuple(random.NextDouble() * 10000, random.Next() + 1); } static Tuple[] RandomValueWeightArray(int count) @@ -687,7 +687,11 @@ static Tuple DefinedValueWeight(double value, long weight) private static double[] WeightedValue(double value, int weight) { double[] values = new double[weight]; - Array.Fill(values, value); + for (var i = 0; i < values.Length; i++) + { + values[i] = value; + } + return values; } } diff --git a/tests/NRedisStack.Tests/TimeSeries/TestAPI/TestMADD.cs b/tests/NRedisStack.Tests/TimeSeries/TestAPI/TestMADD.cs index 83920a69..5aa329bd 100644 --- a/tests/NRedisStack.Tests/TimeSeries/TestAPI/TestMADD.cs +++ b/tests/NRedisStack.Tests/TimeSeries/TestAPI/TestMADD.cs @@ -1,4 +1,5 @@ using NRedisStack.DataTypes; +using NRedisStack.Literals.Enums; using NRedisStack.RedisStackCommands; using StackExchange.Redis; using Xunit; @@ -88,7 +89,7 @@ public void TestOverrideMADD() foreach (string key in keys) { - ts.Create(key); + ts.Create(key, duplicatePolicy: TsDuplicatePolicy.MAX); } List oldTimeStamps = new List(); diff --git a/tests/NRedisStack.Tests/TimeSeries/TestAPI/TestMAddAsync.cs b/tests/NRedisStack.Tests/TimeSeries/TestAPI/TestMAddAsync.cs index 5c7fa550..7778accf 100644 --- a/tests/NRedisStack.Tests/TimeSeries/TestAPI/TestMAddAsync.cs +++ b/tests/NRedisStack.Tests/TimeSeries/TestAPI/TestMAddAsync.cs @@ -1,4 +1,5 @@ using NRedisStack.DataTypes; +using NRedisStack.Literals.Enums; using NRedisStack.RedisStackCommands; using StackExchange.Redis; using Xunit; @@ -82,7 +83,7 @@ public async Task TestOverrideMAdd() foreach (var key in keys) { - await ts.CreateAsync(key); + await ts.CreateAsync(key, duplicatePolicy: TsDuplicatePolicy.MAX); } var oldTimeStamps = new List();