diff --git a/src/NRedisStack/Auxiliary.cs b/src/NRedisStack/Auxiliary.cs index d5555fb7..3a508c2d 100644 --- a/src/NRedisStack/Auxiliary.cs +++ b/src/NRedisStack/Auxiliary.cs @@ -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 MergeArgs(RedisKey key, params RedisValue[] items) { @@ -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) @@ -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; } @@ -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(); @@ -72,8 +69,7 @@ public static RedisResult Execute(this IDatabase db, SerializedCommand command) public async static Task 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(); @@ -135,4 +131,4 @@ public static string GetNRedisStackVersion() return $"{version.Major}.{version.Minor}.{version.Build}"; } } -} \ No newline at end of file +} diff --git a/src/NRedisStack/CoreCommands/CoreCommands.cs b/src/NRedisStack/CoreCommands/CoreCommands.cs index 0040c2bc..4c8917bb 100644 --- a/src/NRedisStack/CoreCommands/CoreCommands.cs +++ b/src/NRedisStack/CoreCommands/CoreCommands.cs @@ -14,6 +14,9 @@ public static class CoreCommands /// 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(); } } diff --git a/src/NRedisStack/CoreCommands/CoreCommandsAsync.cs b/src/NRedisStack/CoreCommands/CoreCommandsAsync.cs index 688d30db..c091159f 100644 --- a/src/NRedisStack/CoreCommands/CoreCommandsAsync.cs +++ b/src/NRedisStack/CoreCommands/CoreCommandsAsync.cs @@ -14,6 +14,11 @@ public static class CoreCommandsAsync //: ICoreCommandsAsync /// public static async Task 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(); } } diff --git a/tests/NRedisStack.Tests/Core Commands/CoreTests.cs b/tests/NRedisStack.Tests/Core Commands/CoreTests.cs index d403dec2..9a3d763a 100644 --- a/tests/NRedisStack.Tests/Core Commands/CoreTests.cs +++ b/tests/NRedisStack.Tests/Core Commands/CoreTests.cs @@ -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")] @@ -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")] @@ -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")] @@ -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")]