Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
<SuppressTfmSupportBuildErrors>true</SuppressTfmSupportBuildErrors>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<NoWarn>$(NoWarn);CS1591;NRS001</NoWarn>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<IsWindows>$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::get_Windows())))</IsWindows>
</PropertyGroup>

Expand Down
3 changes: 0 additions & 3 deletions src/NRedisStack/Experiments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ namespace NRedisStack
internal static class Experiments
{
public const string UrlFormat = "https://redis.github.io/NRedisStack/exp/";

// ReSharper disable once InconsistentNaming
public const string Server_8_4 = "NRS001";
}
}

Expand Down
43 changes: 36 additions & 7 deletions src/NRedisStack/Json/JsonCommandBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using NRedisStack.Json.DataTypes;
using System.ComponentModel;
using System.Diagnostics;
using NRedisStack.Json.DataTypes;
using NRedisStack.Json.Literals;
using NRedisStack.RedisStackCommands;
using StackExchange.Redis;
Expand All @@ -16,14 +18,41 @@ public static SerializedCommand Resp(RedisKey key, string? path = null)
: new SerializedCommand(JSON.RESP, key, path!);
}

public static SerializedCommand Set(RedisKey key, RedisValue path, RedisValue json, When when = When.Always)
#if DEBUG // avoid internal use
[Obsolete("Specify FPHA explicitly", true)]
#endif
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public static SerializedCommand Set(RedisKey key, RedisValue path, RedisValue json, When when)
=> Set(key, path, json, when, JsonNumericArrayStorage.NotSpecified);

public static SerializedCommand Set(RedisKey key, RedisValue path, RedisValue json, When when = When.Always, JsonNumericArrayStorage fpha = JsonNumericArrayStorage.NotSpecified)
{
return when switch
int count = 3;
if (when is (When.Exists or When.NotExists)) count++;
if (fpha != JsonNumericArrayStorage.NotSpecified) count += 2;
object[] args = new object[count];
args[0] = key;
args[1] = path;
args[2] = json;
int i = 3;
if (when is (When.Exists or When.NotExists))
{
args[i++] = when == When.Exists ? "XX" : "NX";
}
if (fpha != JsonNumericArrayStorage.NotSpecified)
{
When.Exists => new(JSON.SET, key, path, json, "XX"),
When.NotExists => new(JSON.SET, key, path, json, "NX"),
_ => new(JSON.SET, key, path, json)
};
args[i++] = "FPHA";
args[i++] = fpha switch
{
JsonNumericArrayStorage.BF16 => "BF16",
JsonNumericArrayStorage.FP16 => "FP16",
JsonNumericArrayStorage.FP32 => "FP32",
JsonNumericArrayStorage.FP64 => "FP64",
_ => fpha.ToString(),
};
}
Debug.Assert(i == count, "Arg count mismatch; check {nameof(Set)}");
Comment thread
mgravell marked this conversation as resolved.
Resolved
return new(JSON.SET, args);
}

public static SerializedCommand MSet(KeyPathValue[] KeyPathValueList)
Expand Down
24 changes: 17 additions & 7 deletions src/NRedisStack/Json/JsonCommands.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NRedisStack.Json.DataTypes;
using System.ComponentModel;
using NRedisStack.Json.DataTypes;
using StackExchange.Redis;
using System.Text.Json;
using System.Text.Json.Nodes;
Expand All @@ -20,19 +21,28 @@ public RedisResult[] Resp(RedisKey key, string? path = null)
return (RedisResult[])result!;
}

/// <inheritdoc/>
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public bool Set(RedisKey key, RedisValue path, object obj, When when, JsonSerializerOptions? serializerOptions)
=> Set(key, path, JsonSerializer.Serialize(obj, serializerOptions), when, JsonNumericArrayStorage.NotSpecified);

/// <inheritdoc/>
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public bool Set(RedisKey key, RedisValue path, RedisValue json, When when)
=> Set(key, path, json, when, JsonNumericArrayStorage.NotSpecified);
Comment on lines +25 to +32

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

we will keep these until major release, right ?
how about marking them obsolete (also as reminder) here and in async as well?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It isn't a good idea to mark them obsolete, as that will cause unnecessary build warnings/failures (depending on build settings) when the exact combination is specified; I try to avoid drama if at all possible.


/// <inheritdoc/>
public bool Set(RedisKey key, RedisValue path, object obj, When when = When.Always,
JsonSerializerOptions? serializerOptions = default)
JsonSerializerOptions? serializerOptions = default, JsonNumericArrayStorage fpha = JsonNumericArrayStorage.NotSpecified)
{
string json = JsonSerializer.Serialize(obj, options: serializerOptions);
return Set(key, path, json, when);
return Set(key, path, json, when, fpha);
}

/// <inheritdoc/>
public bool Set(RedisKey key, RedisValue path, RedisValue json, When when = When.Always)
{
return db.Execute(JsonCommandBuilder.Set(key, path, json, when)).OKtoBoolean();
}
public bool Set(RedisKey key, RedisValue path, RedisValue json, When when = When.Always, JsonNumericArrayStorage fpha = JsonNumericArrayStorage.NotSpecified)
=> db.Execute(JsonCommandBuilder.Set(key, path, json, when, fpha)).OKtoBoolean();


/// <inheritdoc/>
public bool MSet(KeyPathValue[] KeyPathValueList)
Expand Down
21 changes: 16 additions & 5 deletions src/NRedisStack/Json/JsonCommandsAsync.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NRedisStack.Json.DataTypes;
using System.ComponentModel;
using NRedisStack.Json.DataTypes;
using StackExchange.Redis;
using System.Text.Json;
using System.Text.Json.Nodes;
Expand Down Expand Up @@ -125,17 +126,27 @@ public async Task<RedisResult[]> RespAsync(RedisKey key, string? path = null)
return (RedisResult[])result!;
}

/// <inheritdoc/>
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public Task<bool> SetAsync(RedisKey key, RedisValue path, object obj, When when, JsonSerializerOptions? serializerOptions)
=> SetAsync(key, path, obj, when, serializerOptions, JsonNumericArrayStorage.NotSpecified);

/// <inheritdoc/>
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public Task<bool> SetAsync(RedisKey key, RedisValue path, RedisValue json, When when)
=> SetAsync(key, path, json, when, JsonNumericArrayStorage.NotSpecified);

/// <inheritdoc/>
public Task<bool> SetAsync(RedisKey key, RedisValue path, object obj, When when = When.Always,
JsonSerializerOptions? serializerOptions = default)
JsonSerializerOptions? serializerOptions = default, JsonNumericArrayStorage fpha = JsonNumericArrayStorage.NotSpecified)
{
string json = JsonSerializer.Serialize(obj, options: serializerOptions);
return SetAsync(key, path, json, when);
return SetAsync(key, path, json, when, fpha);
}

public async Task<bool> SetAsync(RedisKey key, RedisValue path, RedisValue json, When when = When.Always)
public async Task<bool> SetAsync(RedisKey key, RedisValue path, RedisValue json, When when = When.Always, JsonNumericArrayStorage fpha = JsonNumericArrayStorage.NotSpecified)
{
return (await db.ExecuteAsync(JsonCommandBuilder.Set(key, path, json, when))).OKtoBoolean();
return (await db.ExecuteAsync(JsonCommandBuilder.Set(key, path, json, when, fpha))).OKtoBoolean();
}

public async Task<bool> MSetAsync(KeyPathValue[] KeyPathValueList)
Expand Down
32 changes: 32 additions & 0 deletions src/NRedisStack/Json/JsonNumericArrayStorage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
namespace NRedisStack;

/// <summary>
/// Specifies the storage type for numeric values when used in a JSON array.
/// </summary>
public enum JsonNumericArrayStorage
{
/// <summary>
/// Default behaviour, no FPHA usage.
/// </summary>
NotSpecified = 0,

/// <summary>
/// "Brain" floating-point 16-bit.
/// </summary>
BF16 = 1,

/// <summary>
/// IEEE 754 16-bit.
/// </summary>
FP16 = 2,

/// <summary>
/// IEEE 754 32-bit.
/// </summary>
FP32 = 3,

/// <summary>
/// IEEE 754 64-bit.
/// </summary>
FP64 = 4,
}
2 changes: 1 addition & 1 deletion src/NRedisStack/Json/JsonType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ public enum JsonType
STRING = 5,
ARRAY = 6,
OBJECT = 7
}
}
Loading
Loading