Skip to content

Target .NET Standard 2.0 #89

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 42 commits into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
5a3aaef
Target .NET Standard 2.0
shacharPash Mar 9, 2023
353053a
add condition
shacharPash Mar 9, 2023
d1299c2
update to the latest version of System.Text.Json
shacharPash Mar 12, 2023
8233ccd
adjustments to run in .NET Framework, adding job to run tests for .NE…
slorello89 Mar 13, 2023
a4fcf10
adjustments to run in .NET Framework, adding job to run tests for .NE…
slorello89 Mar 13, 2023
6fee86d
syntax fix
chayim Mar 13, 2023
afc8d70
Merge branch 'Target2.0' of https://github.com/redis/NRedisStack into…
slorello89 Mar 13, 2023
ba18d97
trying to manually switch to linux containers
slorello89 Mar 13, 2023
cb6d25f
trying other format
slorello89 Mar 13, 2023
249c59e
fixing syntax
slorello89 Mar 13, 2023
cc96c41
swapping flags
slorello89 Mar 13, 2023
4769cc7
nixing windows job
slorello89 Mar 13, 2023
91186b5
try dropping framework restrictions
slorello89 Mar 13, 2023
5e4ade5
dropping 462
slorello89 Mar 13, 2023
cf0bf17
trying to test on windows using WSL 2
slorello89 Mar 14, 2023
a825792
adding curl install
slorello89 Mar 14, 2023
9057a87
also installing gpg. . .
slorello89 Mar 14, 2023
1456dd5
and lsb-release...
slorello89 Mar 14, 2023
3b109c0
trying to log start
slorello89 Mar 14, 2023
c01249b
switching to ubuntu
slorello89 Mar 14, 2023
c532b10
change test name
shacharPash Mar 14, 2023
bf0bf8a
delete distribution: Ubuntu-20.04 line
shacharPash Mar 14, 2023
cfcc786
experiment
shacharPash Mar 14, 2023
9488210
trying with direct tar download
slorello89 Mar 14, 2023
b0a524c
ok let's actually add it this time
slorello89 Mar 14, 2023
7137f09
resetting as a jammy instance, adding a ls for debugging
slorello89 Mar 14, 2023
3121220
removing mv
slorello89 Mar 14, 2023
72d2d0c
removing process spinoff
slorello89 Mar 14, 2023
b56c34f
fixing syntax
slorello89 Mar 14, 2023
4d5dde2
libgomp1?
slorello89 Mar 14, 2023
e206725
spin off again
slorello89 Mar 14, 2023
ae849fc
trying a new tact for spinning off process
slorello89 Mar 14, 2023
f193985
old school spin off?
slorello89 Mar 14, 2023
6dde211
renaming
slorello89 Mar 15, 2023
05c580d
versioning
slorello89 Mar 15, 2023
e4f6a6b
newline
slorello89 Mar 15, 2023
dd9e835
PS variable access
slorello89 Mar 15, 2023
4094afe
reverting
slorello89 Mar 15, 2023
1b20013
other means of seeding env vars?
slorello89 Mar 15, 2023
4643fbf
add sleep to HSETandSearch test
shacharPash Mar 15, 2023
e10b00e
add sleep to TestQueryCommandBuilderScore Test
shacharPash Mar 15, 2023
3e1f598
conditional framework usage based on platform
slorello89 Mar 15, 2023
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
12 changes: 10 additions & 2 deletions src/NRedisStack/Graph/Header.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ internal Header(RedisResult result)
SchemaTypes = new List<ResultSetColumnTypes>();
SchemaNames = new List<string>();

foreach(RedisResult[] tuple in (RedisResult[])result)
foreach (RedisResult[] tuple in (RedisResult[])result)
{
SchemaTypes.Add((ResultSetColumnTypes)(int)tuple[0]);
SchemaNames.Add((string)tuple[1]);
Expand Down Expand Up @@ -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)}]}}";
}
Expand Down
16 changes: 8 additions & 8 deletions src/NRedisStack/Json/JsonCommands.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using StackExchange.Redis;
using System.Text.Json;
using System.Text.Json.Nodes;
// using System.Text.Json.Nodes;

namespace NRedisStack;

Expand Down Expand Up @@ -42,12 +42,12 @@ public bool Set(RedisKey key, RedisValue path, RedisValue json, When when = When
/// <inheritdoc/>
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);
}

Expand All @@ -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++;
}
Expand Down Expand Up @@ -111,12 +111,12 @@ public JsonType[] Type(RedisKey key, string? path = null)

if (result.Type == ResultType.MultiBulk)
{
return ((RedisResult[])result!).Select(x => Enum.Parse<JsonType>(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<JsonType>(result.ToString()!.ToUpper()) };
return new[] { (JsonType)Enum.Parse(typeof(JsonType), result.ToString()!.ToUpper()) };
}

return Array.Empty<JsonType>();
Expand Down Expand Up @@ -207,8 +207,8 @@ public RedisResult Get(RedisKey key, string[] paths, RedisValue? indent = null,
var res = _db.Execute(JsonCommandBuilder.Get<T>(key, path));
if (res.Type == ResultType.BulkString)
{
var arr = JsonSerializer.Deserialize<JsonArray>(res.ToString()!);
if (arr?.Count > 0)
var arr = JsonSerializer.Deserialize<JsonElement[]>(res.ToString()!);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

if (arr?.Length > 0)
{
return JsonSerializer.Deserialize<T>(JsonSerializer.Serialize(arr[0]));
}
Expand Down
11 changes: 6 additions & 5 deletions src/NRedisStack/Json/JsonCommandsAsync.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using StackExchange.Redis;
using System.Text.Json;
using System.Text.Json.Nodes;
// using System.Text.Json.Nodes;

namespace NRedisStack;

Expand Down Expand Up @@ -82,8 +82,8 @@ public async Task<RedisResult> GetAsync(RedisKey key, string[] paths, RedisValue
var res = await _db.ExecuteAsync(JsonCommandBuilder.Get<T>(key, path));
if (res.Type == ResultType.BulkString)
{
var arr = JsonSerializer.Deserialize<JsonArray>(res.ToString()!);
if (arr?.Count > 0)
var arr = JsonSerializer.Deserialize<JsonElement[]>(res.ToString()!);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to move this to a JsonElement[] as opposed to a JsonArray?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After I added netstandard2.0 to TargetFrameworks, I got this error:
The type or namespace name 'JsonArray' could not be found (are you missing a using directive or an assembly reference?) [NRedisStack]csharp(CS0246)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's because you are using an older version of System.Text.Json - I think you SHOULD be able to switch it to 7.0.2 (current version) without breaking compatibility. The best way to validate that would be to make sure that

<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
points to some older versions of .NET Framework (e.g. 4.5.2)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you mean to change the Version in this line: <PackageReference Include="System.Text.Json" Version="4.7.1" Condition="'$(TargetFramework)' == 'netstandard2.0'" />
to 7.0.2?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No - so in this case we want to also test against an additional framework (just to make sure that the library is going to be fully compatible with that framework) .NET 4.5.2 is the oldest supported framework in .NET Standard 2.0 - so you just add net452 to the semi-colon delaminated list of target frameworks. You will need to enable this to run on the windows-latest runner in your integration job since .NET Framework can't run on Ubuntu. And you'll need to adjust your dotnet test command to specify the frameworks with the -f option in each job. See docs here

if (arr?.Length > 0)
{
return JsonSerializer.Deserialize<T>(JsonSerializer.Serialize(arr[0]));
}
Expand All @@ -92,6 +92,7 @@ public async Task<RedisResult> GetAsync(RedisKey key, string[] paths, RedisValue
return default;
}


/// <inheritdoc/>
public async Task<IEnumerable<T?>> GetEnumerableAsync<T>(RedisKey key, string path = "$")
{
Expand Down Expand Up @@ -209,12 +210,12 @@ public async Task<JsonType[]> TypeAsync(RedisKey key, string? path = null)

if (result.Type == ResultType.MultiBulk)
{
return ((RedisResult[])result!).Select(x => Enum.Parse<JsonType>(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<JsonType>(result.ToString()!.ToUpper()) };
return new[] { (JsonType)Enum.Parse(typeof(JsonType), result.ToString()!.ToUpper()) };
}

return Array.Empty<JsonType>();
Expand Down
8 changes: 5 additions & 3 deletions src/NRedisStack/NRedisStack.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Nullable>enable</Nullable>
<TargetFrameworks>netstandard2.0;net6.0;net7.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Authors>Redis Open Source</Authors>
<Owners>Redis OSS</Owners>
<Description>.Net Client for Redis Stack</Description>
Expand All @@ -14,6 +15,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.Text.Json" Version="4.7.1" />
<PackageReference Include="StackExchange.Redis" Version="2.6.90" />
<None Include="..\..\README.md" Pack="true" PackagePath="\" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/NRedisStack/ResponseParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ public static IEnumerable<HashSet<string>> 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<string>(keys));
return sets;
}

Expand Down