Skip to content
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

Fix SETINFO Format #203

Merged
merged 6 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 6 additions & 10 deletions src/NRedisStack/Auxiliary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ namespace NRedisStack
{
public static class Auxiliary
{
private static string? _libraryName = $"NRedisStack;.NET-{Environment.Version}";
private static string? _libraryName = $"NRedisStack(.NET_v{Environment.Version})";
private static bool _setInfo = true;
public static void ResetInfoDefaults()
{
_setInfo = true;
_libraryName = $"NRedisStack;.NET-{Environment.Version}";
_libraryName = $"NRedisStack(.NET_v{Environment.Version})";
}
public static List<object> MergeArgs(RedisKey key, params RedisValue[] items)
{
Expand All @@ -34,8 +34,6 @@ public static object[] AssembleNonNullArguments(params object?[] arguments)
return args.ToArray();
}

// public static IDatabase GetDatabase(this ConnectionMultiplexer redis) => redis.GetDatabase("", "");

// TODO: add all the signatures of GetDatabase
public static IDatabase GetDatabase(this ConnectionMultiplexer redis,
string? LibraryName)
Expand All @@ -45,7 +43,7 @@ public static IDatabase GetDatabase(this ConnectionMultiplexer redis,
_setInfo = false;

else // the user set his own the library name
_libraryName = $"NRedisStack({LibraryName});.NET-{Environment.Version})";
_libraryName = $"NRedisStack({LibraryName};.NET_v{Environment.Version})";

return _db;
}
Expand All @@ -61,8 +59,7 @@ private static void SetInfoInPipeline(this IDatabase db)

public static RedisResult Execute(this IDatabase db, SerializedCommand command)
{
var compareVersions = db.Multiplexer.GetServer(db.Multiplexer.GetEndPoints()[0]).Version.CompareTo(new Version(7, 1, 242));
if (_setInfo && compareVersions >= 0)
if (_setInfo)
{
_setInfo = false;
db.SetInfoInPipeline();
Expand All @@ -72,8 +69,7 @@ public static RedisResult Execute(this IDatabase db, SerializedCommand command)

public async static Task<RedisResult> ExecuteAsync(this IDatabaseAsync db, SerializedCommand command)
{
var compareVersions = db.Multiplexer.GetServer(db.Multiplexer.GetEndPoints()[0]).Version.CompareTo(new Version(7, 1, 242));
if (_setInfo && compareVersions >= 0)
if (_setInfo)
{
_setInfo = false;
((IDatabase)db).SetInfoInPipeline();
Expand Down Expand Up @@ -135,4 +131,4 @@ public static string GetNRedisStackVersion()
return $"{version.Major}.{version.Minor}.{version.Build}";
}
}
}
}
3 changes: 3 additions & 0 deletions src/NRedisStack/CoreCommands/CoreCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public static class CoreCommands
/// <remarks><seealso href="https://redis.io/commands/client-setinfo/"/></remarks>
public static bool ClientSetInfo(this IDatabase db, SetInfoAttr attr, string value)
{
var compareVersions = db.Multiplexer.GetServer(db.Multiplexer.GetEndPoints()[0]).Version.CompareTo(new Version(7, 1, 242));
if (compareVersions < 0) // the server does not support the CLIENT SETNAME command
return false;
return db.Execute(CoreCommandBuilder.ClientSetInfo(attr, value)).OKtoBoolean();
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/NRedisStack/CoreCommands/CoreCommandsAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ public static class CoreCommandsAsync //: ICoreCommandsAsync
/// <remarks><seealso href="https://redis.io/commands/client-setinfo/"/></remarks>
public static async Task<bool> ClientSetInfoAsync(this IDatabaseAsync db, SetInfoAttr attr, string value)
{
var compareVersions = db.Multiplexer.GetServer(db.Multiplexer.GetEndPoints()[0]).Version.CompareTo(new Version(7, 1, 242));
if (compareVersions < 0) // the server does not support the CLIENT SETNAME command
{
return false;
}
return (await db.ExecuteAsync(CoreCommandBuilder.ClientSetInfo(attr, value))).OKtoBoolean();
}
}
Expand Down
8 changes: 4 additions & 4 deletions tests/NRedisStack.Tests/Core Commands/CoreTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void TestSetInfoDefaultValue()
db.Execute(new SerializedCommand("PING")); // only the extension method of Execute (which is used for all the commands of Redis Stack) will set the library name and version.

var info = db.Execute("CLIENT", "INFO").ToString();
Assert.EndsWith($"lib-name=NRedisStack;.NET-{Environment.Version} lib-ver={GetNRedisStackVersion()}\n", info);
Assert.EndsWith($"lib-name=NRedisStack(.NET_v{Environment.Version}) lib-ver={GetNRedisStackVersion()}\n", info);
}

[SkipIfRedis(Is.OSSCluster, Comparison.LessThan, "7.1.242")]
Expand All @@ -68,7 +68,7 @@ public async Task TestSetInfoDefaultValueAsync()
await db.ExecuteAsync(new SerializedCommand("PING")); // only the extension method of Execute (which is used for all the commands of Redis Stack) will set the library name and version.

var info = (await db.ExecuteAsync("CLIENT", "INFO")).ToString();
Assert.EndsWith($"lib-name=NRedisStack;.NET-{Environment.Version} lib-ver={GetNRedisStackVersion()}\n", info);
Assert.EndsWith($"lib-name=NRedisStack(.NET_v{Environment.Version}) lib-ver={GetNRedisStackVersion()}\n", info);
}

[SkipIfRedis(Is.OSSCluster, Comparison.LessThan, "7.1.242")]
Expand All @@ -82,7 +82,7 @@ public void TestSetInfoWithValue()
db.Execute(new SerializedCommand("PING")); // only the extension method of Execute (which is used for all the commands of Redis Stack) will set the library name and version.

var info = db.Execute("CLIENT", "INFO").ToString();
Assert.EndsWith($"NRedisStack(MyLibraryName;v1.0.0);.NET-{Environment.Version}) lib-ver={GetNRedisStackVersion()}\n", info);
Assert.EndsWith($"NRedisStack(MyLibraryName;v1.0.0;.NET_v{Environment.Version}) lib-ver={GetNRedisStackVersion()}\n", info);
}

[SkipIfRedis(Is.OSSCluster, Comparison.LessThan, "7.1.242")]
Expand All @@ -96,7 +96,7 @@ public async Task TestSetInfoWithValueAsync()
await db.ExecuteAsync(new SerializedCommand("PING")); // only the extension method of Execute (which is used for all the commands of Redis Stack) will set the library name and version.

var info = (await db.ExecuteAsync("CLIENT", "INFO")).ToString();
Assert.EndsWith($"NRedisStack(MyLibraryName;v1.0.0);.NET-{Environment.Version}) lib-ver={GetNRedisStackVersion()}\n", info);
Assert.EndsWith($"NRedisStack(MyLibraryName;v1.0.0;.NET_v{Environment.Version}) lib-ver={GetNRedisStackVersion()}\n", info);
}

[SkipIfRedis(Is.OSSCluster, Comparison.LessThan, "7.1.242")]
Expand Down