From e496ec310cbe0c3178c045151a97b8444c9b2ac7 Mon Sep 17 00:00:00 2001 From: shacharPash Date: Thu, 24 Aug 2023 16:31:30 +0300 Subject: [PATCH 01/28] deprecated redisGraph --- src/NRedisStack/Graph/IGraphCommands.cs | 1 + src/NRedisStack/Graph/IGraphCommandsAsync.cs | 1 + 2 files changed, 2 insertions(+) diff --git a/src/NRedisStack/Graph/IGraphCommands.cs b/src/NRedisStack/Graph/IGraphCommands.cs index 8995d072..64ba041f 100644 --- a/src/NRedisStack/Graph/IGraphCommands.cs +++ b/src/NRedisStack/Graph/IGraphCommands.cs @@ -3,6 +3,7 @@ namespace NRedisStack { + [Obsolete("RedisGraph is not supported since Redis 7.2 (https://redis.com/blog/redisgraph-eol/)")] public interface IGraphCommands { /// diff --git a/src/NRedisStack/Graph/IGraphCommandsAsync.cs b/src/NRedisStack/Graph/IGraphCommandsAsync.cs index 7ea98ec8..a6d2d36d 100644 --- a/src/NRedisStack/Graph/IGraphCommandsAsync.cs +++ b/src/NRedisStack/Graph/IGraphCommandsAsync.cs @@ -3,6 +3,7 @@ namespace NRedisStack { + [Obsolete("RedisGraph is not supported since Redis 7.2 (https://redis.com/blog/redisgraph-eol/)")] public interface IGraphCommandsAsync { /// From ae8f952183306340307e95232fa6e22d515dec65 Mon Sep 17 00:00:00 2001 From: shacharPash Date: Thu, 31 Aug 2023 15:55:15 +0300 Subject: [PATCH 02/28] supporting client SetInfo command --- .../CoreCommands/CoreCommandBuilder.cs | 22 +++++++++++++++++++ src/NRedisStack/CoreCommands/CoreCommands.cs | 22 +++++++++++++++++++ .../CoreCommands/CoreCommandsAsync.cs | 20 +++++++++++++++++ .../CoreCommands/Enums/SetInfoAttr.cs | 12 ++++++++++ .../CoreCommands/Literals/CommandArgs.cs | 8 +++++++ .../CoreCommands/Literals/Commands.cs | 11 ++++++++++ src/NRedisStack/NRedisStack.csproj | 2 +- tests/Doc/Doc.csproj | 2 +- .../NRedisStack.Tests.csproj | 2 +- 9 files changed, 98 insertions(+), 3 deletions(-) create mode 100644 src/NRedisStack/CoreCommands/CoreCommandBuilder.cs create mode 100644 src/NRedisStack/CoreCommands/CoreCommands.cs create mode 100644 src/NRedisStack/CoreCommands/CoreCommandsAsync.cs create mode 100644 src/NRedisStack/CoreCommands/Enums/SetInfoAttr.cs create mode 100644 src/NRedisStack/CoreCommands/Literals/CommandArgs.cs create mode 100644 src/NRedisStack/CoreCommands/Literals/Commands.cs diff --git a/src/NRedisStack/CoreCommands/CoreCommandBuilder.cs b/src/NRedisStack/CoreCommands/CoreCommandBuilder.cs new file mode 100644 index 00000000..9677824d --- /dev/null +++ b/src/NRedisStack/CoreCommands/CoreCommandBuilder.cs @@ -0,0 +1,22 @@ +using NRedisStack.RedisStackCommands; +using NRedisStack.Core.Literals; +using NRedisStack.Core; + +namespace NRedisStack +{ + + public static class CoreCommandBuilder + { + public static SerializedCommand ClientSetInfo(SetInfoAttr attr, string value) + { + string attrValue = attr switch + { + SetInfoAttr.LibraryName => CoreArgs.lib_name, + SetInfoAttr.LibraryVersion => CoreArgs.lib_ver, + _ => throw new System.NotImplementedException(), + }; + + return new SerializedCommand(RedisCoreCommands.CLIENT, RedisCoreCommands.SETINFO, attrValue, value); + } + } +} diff --git a/src/NRedisStack/CoreCommands/CoreCommands.cs b/src/NRedisStack/CoreCommands/CoreCommands.cs new file mode 100644 index 00000000..a3312d8e --- /dev/null +++ b/src/NRedisStack/CoreCommands/CoreCommands.cs @@ -0,0 +1,22 @@ +using NRedisStack.Core; +using NRedisStack.Core.Literals; +using StackExchange.Redis; +namespace NRedisStack +{ + + public static class CoreCommands + { + /// + /// Sets information specific to the client or connection. + /// + /// which attribute to set + /// the attribute value + /// if the attribute name was successfully set, Error otherwise. + /// + public static bool ClientSetInfo(this IDatabase db, SetInfoAttr attr, string value) + { + + return db.Execute(CoreCommandBuilder.ClientSetInfo(attr, value)).OKtoBoolean(); + } + } +} diff --git a/src/NRedisStack/CoreCommands/CoreCommandsAsync.cs b/src/NRedisStack/CoreCommands/CoreCommandsAsync.cs new file mode 100644 index 00000000..8de5bb74 --- /dev/null +++ b/src/NRedisStack/CoreCommands/CoreCommandsAsync.cs @@ -0,0 +1,20 @@ +using NRedisStack.Core; +using StackExchange.Redis; +namespace NRedisStack +{ + + public static class CoreCommandsAsync //: ICoreCommandsAsync + { + /// + /// Sets information specific to the client or connection. + /// + /// which attribute to set + /// the attribute value + /// if the attribute name was successfully set, Error otherwise. + /// + public static async Task ClientSetInfoAsync(this IDatabase db, SetInfoAttr attr, string value) + { + return (await db.ExecuteAsync(CoreCommandBuilder.ClientSetInfo(attr, value))).OKtoBoolean(); + } + } +} diff --git a/src/NRedisStack/CoreCommands/Enums/SetInfoAttr.cs b/src/NRedisStack/CoreCommands/Enums/SetInfoAttr.cs new file mode 100644 index 00000000..16f10a9a --- /dev/null +++ b/src/NRedisStack/CoreCommands/Enums/SetInfoAttr.cs @@ -0,0 +1,12 @@ +namespace NRedisStack.Core; +public enum SetInfoAttr +{ + /// + /// meant to hold the name of the client library that's in use. + /// + LibraryName, + /// + /// meant to hold the client library's version. + /// + LibraryVersion +} diff --git a/src/NRedisStack/CoreCommands/Literals/CommandArgs.cs b/src/NRedisStack/CoreCommands/Literals/CommandArgs.cs new file mode 100644 index 00000000..e6af3364 --- /dev/null +++ b/src/NRedisStack/CoreCommands/Literals/CommandArgs.cs @@ -0,0 +1,8 @@ +namespace NRedisStack.Core.Literals +{ + internal class CoreArgs + { + public const string lib_name = "lib-name"; + public const string lib_ver = "lib-ver"; + } +} diff --git a/src/NRedisStack/CoreCommands/Literals/Commands.cs b/src/NRedisStack/CoreCommands/Literals/Commands.cs new file mode 100644 index 00000000..aaebaef6 --- /dev/null +++ b/src/NRedisStack/CoreCommands/Literals/Commands.cs @@ -0,0 +1,11 @@ +namespace NRedisStack.Core.Literals +{ + /// + /// Redis Core command literals + /// + internal class RedisCoreCommands + { + public const string CLIENT = "CLIENT"; + public const string SETINFO = "SETINFO"; + } +} diff --git a/src/NRedisStack/NRedisStack.csproj b/src/NRedisStack/NRedisStack.csproj index 300469d9..c91c2aec 100644 --- a/src/NRedisStack/NRedisStack.csproj +++ b/src/NRedisStack/NRedisStack.csproj @@ -16,7 +16,7 @@ - + diff --git a/tests/Doc/Doc.csproj b/tests/Doc/Doc.csproj index 56fdeec0..4f788fc3 100644 --- a/tests/Doc/Doc.csproj +++ b/tests/Doc/Doc.csproj @@ -16,7 +16,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive all - + diff --git a/tests/NRedisStack.Tests/NRedisStack.Tests.csproj b/tests/NRedisStack.Tests/NRedisStack.Tests.csproj index aa4d38d6..8b264921 100644 --- a/tests/NRedisStack.Tests/NRedisStack.Tests.csproj +++ b/tests/NRedisStack.Tests/NRedisStack.Tests.csproj @@ -22,7 +22,7 @@ - + From d12bf7dae392a2f993baeb11d9bfcd52eca8aaa0 Mon Sep 17 00:00:00 2001 From: shacharPash Date: Thu, 31 Aug 2023 16:51:42 +0300 Subject: [PATCH 03/28] add tests --- .../Core Commands/CoreTests.cs | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 tests/NRedisStack.Tests/Core Commands/CoreTests.cs diff --git a/tests/NRedisStack.Tests/Core Commands/CoreTests.cs b/tests/NRedisStack.Tests/Core Commands/CoreTests.cs new file mode 100644 index 00000000..8da02ec1 --- /dev/null +++ b/tests/NRedisStack.Tests/Core Commands/CoreTests.cs @@ -0,0 +1,47 @@ +using Xunit; +using NRedisStack.Core; + +namespace NRedisStack.Tests.Core; + +public class CoreTests : AbstractNRedisStackTest, IDisposable +{ + private readonly string key = "CORE_TESTS"; + public CoreTests(RedisFixture redisFixture) : base(redisFixture) { } + + public void Dispose() + { + redisFixture.Redis.GetDatabase().KeyDelete(key); + } + + [SkipIfRedisVersion(Comparison.LessThan, "7.1.242")] + public void TestSetInfo() + { + var redis = redisFixture.Redis; + + var db = redis.GetDatabase(); + db.Execute("FLUSHALL"); + var info = db.Execute("CLIENT", "INFO").ToString(); + Assert.EndsWith("lib-name=SE.Redis lib-ver=2.6.122.38350\n", info); + + Assert.True(db.ClientSetInfo(SetInfoAttr.LibraryName, "nredisstack")); + Assert.True(db.ClientSetInfo(SetInfoAttr.LibraryVersion, "0.8.1")); + info = db.Execute("CLIENT", "INFO").ToString(); + Assert.EndsWith("lib-name=nredisstack lib-ver=0.8.1\n", info); + } + + [SkipIfRedisVersion(Comparison.LessThan, "7.1.242")] + public async Task TestSetInfoç() + { + var redis = redisFixture.Redis; + + var db = redis.GetDatabase(); + db.Execute("FLUSHALL"); + var info = (await db.ExecuteAsync("CLIENT", "INFO")).ToString(); + Assert.EndsWith("lib-name=SE.Redis lib-ver=2.6.122.38350\n", info); + + Assert.True( await db.ClientSetInfoAsync(SetInfoAttr.LibraryName, "nredisstack")); + Assert.True( await db.ClientSetInfoAsync(SetInfoAttr.LibraryVersion, "0.8.1")); + info = (await db.ExecuteAsync("CLIENT", "INFO")).ToString(); + Assert.EndsWith("lib-name=nredisstack lib-ver=0.8.1\n", info); + } +} \ No newline at end of file From f59afe00d2a61e41c2bf7f28d1781fe9ef11d3c2 Mon Sep 17 00:00:00 2001 From: shacharPash Date: Thu, 31 Aug 2023 17:11:39 +0300 Subject: [PATCH 04/28] check somthing --- tests/NRedisStack.Tests/Core Commands/CoreTests.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/NRedisStack.Tests/Core Commands/CoreTests.cs b/tests/NRedisStack.Tests/Core Commands/CoreTests.cs index 8da02ec1..97e56f03 100644 --- a/tests/NRedisStack.Tests/Core Commands/CoreTests.cs +++ b/tests/NRedisStack.Tests/Core Commands/CoreTests.cs @@ -23,8 +23,8 @@ public void TestSetInfo() var info = db.Execute("CLIENT", "INFO").ToString(); Assert.EndsWith("lib-name=SE.Redis lib-ver=2.6.122.38350\n", info); - Assert.True(db.ClientSetInfo(SetInfoAttr.LibraryName, "nredisstack")); - Assert.True(db.ClientSetInfo(SetInfoAttr.LibraryVersion, "0.8.1")); + Assert.True(db.ClientSetInfo(SetInfoAttr.LibraryName, "anylibname")); + Assert.True(db.ClientSetInfo(SetInfoAttr.LibraryVersion, "1.2.3")); info = db.Execute("CLIENT", "INFO").ToString(); Assert.EndsWith("lib-name=nredisstack lib-ver=0.8.1\n", info); } @@ -39,8 +39,8 @@ public async Task TestSetInfoç() var info = (await db.ExecuteAsync("CLIENT", "INFO")).ToString(); Assert.EndsWith("lib-name=SE.Redis lib-ver=2.6.122.38350\n", info); - Assert.True( await db.ClientSetInfoAsync(SetInfoAttr.LibraryName, "nredisstack")); - Assert.True( await db.ClientSetInfoAsync(SetInfoAttr.LibraryVersion, "0.8.1")); + Assert.True( await db.ClientSetInfoAsync(SetInfoAttr.LibraryName, "anylibname")); + Assert.True( await db.ClientSetInfoAsync(SetInfoAttr.LibraryVersion, "1.2.3")); info = (await db.ExecuteAsync("CLIENT", "INFO")).ToString(); Assert.EndsWith("lib-name=nredisstack lib-ver=0.8.1\n", info); } From f24cd97dd6b933f1af447e92620946ee6f25ec75 Mon Sep 17 00:00:00 2001 From: shacharPash Date: Thu, 31 Aug 2023 17:18:15 +0300 Subject: [PATCH 05/28] check2 --- tests/NRedisStack.Tests/Core Commands/CoreTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/NRedisStack.Tests/Core Commands/CoreTests.cs b/tests/NRedisStack.Tests/Core Commands/CoreTests.cs index 97e56f03..625a6ae4 100644 --- a/tests/NRedisStack.Tests/Core Commands/CoreTests.cs +++ b/tests/NRedisStack.Tests/Core Commands/CoreTests.cs @@ -26,7 +26,7 @@ public void TestSetInfo() Assert.True(db.ClientSetInfo(SetInfoAttr.LibraryName, "anylibname")); Assert.True(db.ClientSetInfo(SetInfoAttr.LibraryVersion, "1.2.3")); info = db.Execute("CLIENT", "INFO").ToString(); - Assert.EndsWith("lib-name=nredisstack lib-ver=0.8.1\n", info); + Assert.EndsWith("lib-name=anylibname lib-ver=1.2.3\n", info); } [SkipIfRedisVersion(Comparison.LessThan, "7.1.242")] @@ -42,6 +42,6 @@ public async Task TestSetInfoç() Assert.True( await db.ClientSetInfoAsync(SetInfoAttr.LibraryName, "anylibname")); Assert.True( await db.ClientSetInfoAsync(SetInfoAttr.LibraryVersion, "1.2.3")); info = (await db.ExecuteAsync("CLIENT", "INFO")).ToString(); - Assert.EndsWith("lib-name=nredisstack lib-ver=0.8.1\n", info); + Assert.EndsWith("lib-name=anylibname lib-ver=1.2.3\n", info); } } \ No newline at end of file From 2b065b1dd3e43b3376db4ef3e05894c5f5666d2d Mon Sep 17 00:00:00 2001 From: shacharPash Date: Thu, 31 Aug 2023 17:18:31 +0300 Subject: [PATCH 06/28] Async --- tests/NRedisStack.Tests/Core Commands/CoreTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/NRedisStack.Tests/Core Commands/CoreTests.cs b/tests/NRedisStack.Tests/Core Commands/CoreTests.cs index 625a6ae4..5cf7d4a8 100644 --- a/tests/NRedisStack.Tests/Core Commands/CoreTests.cs +++ b/tests/NRedisStack.Tests/Core Commands/CoreTests.cs @@ -30,7 +30,7 @@ public void TestSetInfo() } [SkipIfRedisVersion(Comparison.LessThan, "7.1.242")] - public async Task TestSetInfoç() + public async Task TestSetInfoAsync() { var redis = redisFixture.Redis; From 072504eb1f84c0197695fa9299f51c449ee199b7 Mon Sep 17 00:00:00 2001 From: shacharPash Date: Thu, 31 Aug 2023 17:57:19 +0300 Subject: [PATCH 07/28] try ConnectionMultiplexer.Connect("localhost"); --- tests/NRedisStack.Tests/Core Commands/CoreTests.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/NRedisStack.Tests/Core Commands/CoreTests.cs b/tests/NRedisStack.Tests/Core Commands/CoreTests.cs index 5cf7d4a8..39456341 100644 --- a/tests/NRedisStack.Tests/Core Commands/CoreTests.cs +++ b/tests/NRedisStack.Tests/Core Commands/CoreTests.cs @@ -1,5 +1,6 @@ using Xunit; using NRedisStack.Core; +using StackExchange.Redis; namespace NRedisStack.Tests.Core; @@ -16,9 +17,9 @@ public void Dispose() [SkipIfRedisVersion(Comparison.LessThan, "7.1.242")] public void TestSetInfo() { - var redis = redisFixture.Redis; - + var redis = ConnectionMultiplexer.Connect("localhost"); var db = redis.GetDatabase(); + db.Execute("FLUSHALL"); var info = db.Execute("CLIENT", "INFO").ToString(); Assert.EndsWith("lib-name=SE.Redis lib-ver=2.6.122.38350\n", info); @@ -32,7 +33,7 @@ public void TestSetInfo() [SkipIfRedisVersion(Comparison.LessThan, "7.1.242")] public async Task TestSetInfoAsync() { - var redis = redisFixture.Redis; + var redis = ConnectionMultiplexer.Connect("localhost"); var db = redis.GetDatabase(); db.Execute("FLUSHALL"); From df78947dc86c873cc1974112580a42b2fe57c640 Mon Sep 17 00:00:00 2001 From: shacharPash Date: Wed, 13 Sep 2023 18:26:09 +0300 Subject: [PATCH 08/28] new format --- src/NRedisStack/Auxiliary.cs | 64 +++++++++++++++++++ .../CoreCommands/CoreCommandsAsync.cs | 2 +- .../Core Commands/CoreTests.cs | 16 +++-- 3 files changed, 75 insertions(+), 7 deletions(-) diff --git a/src/NRedisStack/Auxiliary.cs b/src/NRedisStack/Auxiliary.cs index 2dcde416..09a0c0f5 100644 --- a/src/NRedisStack/Auxiliary.cs +++ b/src/NRedisStack/Auxiliary.cs @@ -1,3 +1,8 @@ +using System.Diagnostics; +using System.IO.Pipelines; +using System.Reflection; +using System.Xml.Linq; +using NRedisStack.Core; using NRedisStack.RedisStackCommands; using StackExchange.Redis; @@ -26,6 +31,30 @@ public static object[] AssembleNonNullArguments(params object?[] arguments) return args.ToArray(); } + public static IDatabase GetDatabase(this ConnectionMultiplexer redis, + string? LibraryName = "", + string? LibraryVersion = "") + { + var _db = redis.GetDatabase(); + if(LibraryName == null && LibraryVersion == null) + { + return _db; + } + + // Set the default values for LibraryName and LibraryVersion if they are not set. + if (LibraryName == "") + LibraryName = $"NRedisStack(SE.Redis-v{GetStackExchangeRedisVersion()};.NET-{Environment.Version})"; + if (LibraryVersion == "") + LibraryVersion = GetNRedisStackVersion(); + + Pipeline pipeline = new Pipeline(_db); + _ = pipeline.Db.ClientSetInfoAsync(SetInfoAttr.LibraryName, LibraryName!); + _ = pipeline.Db.ClientSetInfoAsync(SetInfoAttr.LibraryVersion, LibraryVersion!); + pipeline.Execute(); + + return _db; + } + public static RedisResult Execute(this IDatabase db, SerializedCommand command) { return db.Execute(command.Command, command.Args); @@ -35,5 +64,40 @@ public async static Task ExecuteAsync(this IDatabaseAsync db, Seria { return await db.ExecuteAsync(command.Command, command.Args); } + + public static string GetNRedisStackVersion() + { + XDocument csprojDocument = GetCsprojDocument(); + + // Find the Version element and get its value. + var versionElement = csprojDocument.Root! + .Descendants("Version") + .FirstOrDefault(); + + return versionElement!.Value; + } + + public static string GetStackExchangeRedisVersion() + { + XDocument csprojDocument = GetCsprojDocument(); + + // Find the PackageReference element with Include="StackExchange.Redis" and get its Version attribute. + var stackExchangeRedisVersion = csprojDocument.Root! + .Descendants("PackageReference") + .Where(element => element.Attribute("Include")?.Value == "StackExchange.Redis") + .Select(element => element.Attribute("Version")?.Value) + .FirstOrDefault(); + + return stackExchangeRedisVersion!; + } + + private static XDocument GetCsprojDocument() + { + string csprojFilePath = Path.Combine(Directory.GetCurrentDirectory(), "..", "..", "..", "..", "..", "src", "NRedisStack", "NRedisStack.csproj"); + + // Load the .csproj file. + var csprojDocument = XDocument.Load(csprojFilePath); + return csprojDocument; + } } } \ No newline at end of file diff --git a/src/NRedisStack/CoreCommands/CoreCommandsAsync.cs b/src/NRedisStack/CoreCommands/CoreCommandsAsync.cs index 8de5bb74..688d30db 100644 --- a/src/NRedisStack/CoreCommands/CoreCommandsAsync.cs +++ b/src/NRedisStack/CoreCommands/CoreCommandsAsync.cs @@ -12,7 +12,7 @@ public static class CoreCommandsAsync //: ICoreCommandsAsync /// the attribute value /// if the attribute name was successfully set, Error otherwise. /// - public static async Task ClientSetInfoAsync(this IDatabase db, SetInfoAttr attr, string value) + public static async Task ClientSetInfoAsync(this IDatabaseAsync db, SetInfoAttr attr, string value) { 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 39456341..064745fa 100644 --- a/tests/NRedisStack.Tests/Core Commands/CoreTests.cs +++ b/tests/NRedisStack.Tests/Core Commands/CoreTests.cs @@ -1,6 +1,10 @@ using Xunit; using NRedisStack.Core; +using static NRedisStack.Auxiliary; using StackExchange.Redis; +using System.Xml.Linq; +using System.Reflection; + namespace NRedisStack.Tests.Core; @@ -18,11 +22,11 @@ public void Dispose() public void TestSetInfo() { var redis = ConnectionMultiplexer.Connect("localhost"); - var db = redis.GetDatabase(); + var db = redis.GetDatabase("",""); // TODO: find a way that the user will not need to pass the library name and version if he wants to use the default values. db.Execute("FLUSHALL"); var info = db.Execute("CLIENT", "INFO").ToString(); - Assert.EndsWith("lib-name=SE.Redis lib-ver=2.6.122.38350\n", info); + Assert.EndsWith($"lib-name=NRedisStack(SE.Redis-v{GetStackExchangeRedisVersion()};.NET-{Environment.Version}) lib-ver={GetNRedisStackVersion()}\n", info); Assert.True(db.ClientSetInfo(SetInfoAttr.LibraryName, "anylibname")); Assert.True(db.ClientSetInfo(SetInfoAttr.LibraryVersion, "1.2.3")); @@ -35,13 +39,13 @@ public async Task TestSetInfoAsync() { var redis = ConnectionMultiplexer.Connect("localhost"); - var db = redis.GetDatabase(); + var db = redis.GetDatabase("", ""); // TODO: find a way that the user will not need to pass the library name and version if he wants to use the default values. db.Execute("FLUSHALL"); var info = (await db.ExecuteAsync("CLIENT", "INFO")).ToString(); - Assert.EndsWith("lib-name=SE.Redis lib-ver=2.6.122.38350\n", info); + Assert.EndsWith($"lib-name=NRedisStack(SE.Redis-v{GetStackExchangeRedisVersion()};.NET-{Environment.Version}) lib-ver={GetNRedisStackVersion()}\n", info); - Assert.True( await db.ClientSetInfoAsync(SetInfoAttr.LibraryName, "anylibname")); - Assert.True( await db.ClientSetInfoAsync(SetInfoAttr.LibraryVersion, "1.2.3")); + Assert.True(await db.ClientSetInfoAsync(SetInfoAttr.LibraryName, "anylibname")); + Assert.True(await db.ClientSetInfoAsync(SetInfoAttr.LibraryVersion, "1.2.3")); info = (await db.ExecuteAsync("CLIENT", "INFO")).ToString(); Assert.EndsWith("lib-name=anylibname lib-ver=1.2.3\n", info); } From 522bb910081410253cda23658a578801fac88e22 Mon Sep 17 00:00:00 2001 From: shacharPash Date: Thu, 14 Sep 2023 12:18:49 +0300 Subject: [PATCH 09/28] fix core tests --- tests/NRedisStack.Tests/Core Commands/CoreTests.cs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/tests/NRedisStack.Tests/Core Commands/CoreTests.cs b/tests/NRedisStack.Tests/Core Commands/CoreTests.cs index 064745fa..61d73cf5 100644 --- a/tests/NRedisStack.Tests/Core Commands/CoreTests.cs +++ b/tests/NRedisStack.Tests/Core Commands/CoreTests.cs @@ -13,12 +13,7 @@ public class CoreTests : AbstractNRedisStackTest, IDisposable private readonly string key = "CORE_TESTS"; public CoreTests(RedisFixture redisFixture) : base(redisFixture) { } - public void Dispose() - { - redisFixture.Redis.GetDatabase().KeyDelete(key); - } - - [SkipIfRedisVersion(Comparison.LessThan, "7.1.242")] + [SkipIfRedis(Comparison.LessThan, "7.1.242")] public void TestSetInfo() { var redis = ConnectionMultiplexer.Connect("localhost"); @@ -34,7 +29,7 @@ public void TestSetInfo() Assert.EndsWith("lib-name=anylibname lib-ver=1.2.3\n", info); } - [SkipIfRedisVersion(Comparison.LessThan, "7.1.242")] + [SkipIfRedis(Comparison.LessThan, "7.1.242")] public async Task TestSetInfoAsync() { var redis = ConnectionMultiplexer.Connect("localhost"); From 0ae22fb8578346588b1873520e5d1396228a751a Mon Sep 17 00:00:00 2001 From: shacharPash Date: Mon, 18 Sep 2023 15:55:43 +0300 Subject: [PATCH 10/28] try change to IDatabase instead of IDatabaseAsync --- src/NRedisStack/Auxiliary.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/NRedisStack/Auxiliary.cs b/src/NRedisStack/Auxiliary.cs index 951c40d0..d9abc100 100644 --- a/src/NRedisStack/Auxiliary.cs +++ b/src/NRedisStack/Auxiliary.cs @@ -60,15 +60,15 @@ public static RedisResult Execute(this IDatabase db, SerializedCommand command) return db.Execute(command.Command, command.Args); } - public async static Task ExecuteAsync(this IDatabaseAsync db, SerializedCommand command) + public async static Task ExecuteAsync(this IDatabase db, SerializedCommand command) { return await db.ExecuteAsync(command.Command, command.Args); } - public static List ExecuteBroadcast(this IDatabaseAsync db, string command) + public static List ExecuteBroadcast(this IDatabase db, string command) => db.ExecuteBroadcast(new SerializedCommand(command)); - public static List ExecuteBroadcast(this IDatabaseAsync db, SerializedCommand command) + public static List ExecuteBroadcast(this IDatabase db, SerializedCommand command) { var redis = db.Multiplexer; var endpoints = redis.GetEndPoints(); @@ -89,10 +89,10 @@ public static List ExecuteBroadcast(this IDatabaseAsync db, Seriali return results; } - public async static Task> ExecuteBroadcastAsync(this IDatabaseAsync db, string command) + public async static Task> ExecuteBroadcastAsync(this IDatabase db, string command) => await db.ExecuteBroadcastAsync(new SerializedCommand(command)); - public async static Task> ExecuteBroadcastAsync(this IDatabaseAsync db, SerializedCommand command) + public async static Task> ExecuteBroadcastAsync(this IDatabase db, SerializedCommand command) { var redis = db.Multiplexer; var endpoints = redis.GetEndPoints(); From c79fe403f1f96673e5c60412e6606a5e673f456d Mon Sep 17 00:00:00 2001 From: shacharPash Date: Tue, 19 Sep 2023 11:04:04 +0300 Subject: [PATCH 11/28] add bool _setinfo to Auxiliary --- src/NRedisStack/Auxiliary.cs | 49 +++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/src/NRedisStack/Auxiliary.cs b/src/NRedisStack/Auxiliary.cs index d9abc100..ae89d710 100644 --- a/src/NRedisStack/Auxiliary.cs +++ b/src/NRedisStack/Auxiliary.cs @@ -1,6 +1,3 @@ -using System.Diagnostics; -using System.IO.Pipelines; -using System.Reflection; using System.Xml.Linq; using NRedisStack.Core; using NRedisStack.RedisStackCommands; @@ -10,6 +7,8 @@ namespace NRedisStack { public static class Auxiliary { + private static bool _setInfo = false; + private static string _libraryName = ""; public static List MergeArgs(RedisKey key, params RedisValue[] items) { var args = new List(items.Length + 1) { key }; @@ -31,37 +30,53 @@ 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 = "", - string? LibraryVersion = "") + string? LibraryName = "") { var _db = redis.GetDatabase(); - if (LibraryName == null && LibraryVersion == null) + if (LibraryName == null) { return _db; } - // Set the default values for LibraryName and LibraryVersion if they are not set. - if (LibraryName == "") - LibraryName = $"NRedisStack(SE.Redis-v{GetStackExchangeRedisVersion()};.NET-{Environment.Version})"; - if (LibraryVersion == "") - LibraryVersion = GetNRedisStackVersion(); + if (LibraryName != "") + _libraryName = $"NRedisStack({LibraryName});.NET-{Environment.Version})"; + else + _libraryName = $"NRedisStack;.NET-{Environment.Version}"; + + return _db; + } + private static void SetInfoInPipeline(this IDatabase _db, string? LibraryName) + { Pipeline pipeline = new Pipeline(_db); _ = pipeline.Db.ClientSetInfoAsync(SetInfoAttr.LibraryName, LibraryName!); - _ = pipeline.Db.ClientSetInfoAsync(SetInfoAttr.LibraryVersion, LibraryVersion!); + _ = pipeline.Db.ClientSetInfoAsync(SetInfoAttr.LibraryVersion, GetNRedisStackVersion()!); pipeline.Execute(); - - return _db; } public static RedisResult Execute(this IDatabase db, SerializedCommand command) { + if(!_setInfo) + { + db.SetInfoInPipeline(_libraryName); + _setInfo = true; + } return db.Execute(command.Command, command.Args); } - public async static Task ExecuteAsync(this IDatabase db, SerializedCommand command) + public async static Task ExecuteAsync(this IDatabaseAsync db, SerializedCommand command) { + if(!_setInfo) + { + // TODO: check if I can do it in pipeline + _ = db.ClientSetInfoAsync(SetInfoAttr.LibraryName, _libraryName); + _ = db.ClientSetInfoAsync(SetInfoAttr.LibraryVersion, GetNRedisStackVersion()); + _setInfo = true; + } return await db.ExecuteAsync(command.Command, command.Args); } @@ -89,10 +104,10 @@ public static List ExecuteBroadcast(this IDatabase db, SerializedCo return results; } - public async static Task> ExecuteBroadcastAsync(this IDatabase db, string command) + public async static Task> ExecuteBroadcastAsync(this IDatabaseAsync db, string command) => await db.ExecuteBroadcastAsync(new SerializedCommand(command)); - public async static Task> ExecuteBroadcastAsync(this IDatabase db, SerializedCommand command) + public async static Task> ExecuteBroadcastAsync(this IDatabaseAsync db, SerializedCommand command) { var redis = db.Multiplexer; var endpoints = redis.GetEndPoints(); From 111e734c376822fb15632476ebdd036eb40d57ab Mon Sep 17 00:00:00 2001 From: shacharPash Date: Tue, 19 Sep 2023 11:06:27 +0300 Subject: [PATCH 12/28] comment CoreTests --- .../Core Commands/CoreTests.cs | 63 ++++++++++--------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/tests/NRedisStack.Tests/Core Commands/CoreTests.cs b/tests/NRedisStack.Tests/Core Commands/CoreTests.cs index 61d73cf5..bbab7f38 100644 --- a/tests/NRedisStack.Tests/Core Commands/CoreTests.cs +++ b/tests/NRedisStack.Tests/Core Commands/CoreTests.cs @@ -1,5 +1,6 @@ using Xunit; using NRedisStack.Core; +using NRedisStack; using static NRedisStack.Auxiliary; using StackExchange.Redis; using System.Xml.Linq; @@ -13,35 +14,35 @@ public class CoreTests : AbstractNRedisStackTest, IDisposable private readonly string key = "CORE_TESTS"; public CoreTests(RedisFixture redisFixture) : base(redisFixture) { } - [SkipIfRedis(Comparison.LessThan, "7.1.242")] - public void TestSetInfo() - { - var redis = ConnectionMultiplexer.Connect("localhost"); - var db = redis.GetDatabase("",""); // TODO: find a way that the user will not need to pass the library name and version if he wants to use the default values. - - db.Execute("FLUSHALL"); - var info = db.Execute("CLIENT", "INFO").ToString(); - Assert.EndsWith($"lib-name=NRedisStack(SE.Redis-v{GetStackExchangeRedisVersion()};.NET-{Environment.Version}) lib-ver={GetNRedisStackVersion()}\n", info); - - Assert.True(db.ClientSetInfo(SetInfoAttr.LibraryName, "anylibname")); - Assert.True(db.ClientSetInfo(SetInfoAttr.LibraryVersion, "1.2.3")); - info = db.Execute("CLIENT", "INFO").ToString(); - Assert.EndsWith("lib-name=anylibname lib-ver=1.2.3\n", info); - } - - [SkipIfRedis(Comparison.LessThan, "7.1.242")] - public async Task TestSetInfoAsync() - { - var redis = ConnectionMultiplexer.Connect("localhost"); - - var db = redis.GetDatabase("", ""); // TODO: find a way that the user will not need to pass the library name and version if he wants to use the default values. - db.Execute("FLUSHALL"); - var info = (await db.ExecuteAsync("CLIENT", "INFO")).ToString(); - Assert.EndsWith($"lib-name=NRedisStack(SE.Redis-v{GetStackExchangeRedisVersion()};.NET-{Environment.Version}) lib-ver={GetNRedisStackVersion()}\n", info); - - Assert.True(await db.ClientSetInfoAsync(SetInfoAttr.LibraryName, "anylibname")); - Assert.True(await db.ClientSetInfoAsync(SetInfoAttr.LibraryVersion, "1.2.3")); - info = (await db.ExecuteAsync("CLIENT", "INFO")).ToString(); - Assert.EndsWith("lib-name=anylibname lib-ver=1.2.3\n", info); - } + // [SkipIfRedis(Comparison.LessThan, "7.1.242")] + // public void TestSetInfo() + // { + // var redis = ConnectionMultiplexer.Connect("localhost"); + // var db = redis.GetDatabase("name"); // TODO: find a way that the user will not need to pass the library name and version if he wants to use the default values. + + // db.Execute("FLUSHALL"); + // var info = db.Execute("CLIENT", "INFO").ToString(); + // Assert.EndsWith($"lib-name=NRedisStack(SE.Redis-v{GetStackExchangeRedisVersion()};.NET-{Environment.Version}) lib-ver={GetNRedisStackVersion()}\n", info); + + // Assert.True(db.ClientSetInfo(SetInfoAttr.LibraryName, "anylibname")); + // Assert.True(db.ClientSetInfo(SetInfoAttr.LibraryVersion, "1.2.3")); + // info = db.Execute("CLIENT", "INFO").ToString(); + // Assert.EndsWith("lib-name=anylibname lib-ver=1.2.3\n", info); + // } + + // [SkipIfRedis(Comparison.LessThan, "7.1.242")] + // public async Task TestSetInfoAsync() + // { + // var redis = ConnectionMultiplexer.Connect("localhost"); + + // var db = redis.GetDatabase(""); // TODO: find a way that the user will not need to pass the library name and version if he wants to use the default values. + // db.Execute("FLUSHALL"); + // var info = (await db.ExecuteAsync("CLIENT", "INFO")).ToString(); + // Assert.EndsWith($"lib-name=NRedisStack(SE.Redis-v{GetStackExchangeRedisVersion()};.NET-{Environment.Version}) lib-ver={GetNRedisStackVersion()}\n", info); + + // Assert.True(await db.ClientSetInfoAsync(SetInfoAttr.LibraryName, "anylibname")); + // Assert.True(await db.ClientSetInfoAsync(SetInfoAttr.LibraryVersion, "1.2.3")); + // info = (await db.ExecuteAsync("CLIENT", "INFO")).ToString(); + // Assert.EndsWith("lib-name=anylibname lib-ver=1.2.3\n", info); + // } } \ No newline at end of file From f6cac53e1d2672f9e4783d32218156d94f64eae0 Mon Sep 17 00:00:00 2001 From: shacharPash Date: Tue, 19 Sep 2023 14:06:11 +0300 Subject: [PATCH 13/28] fix Aux --- src/NRedisStack/Auxiliary.cs | 37 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/src/NRedisStack/Auxiliary.cs b/src/NRedisStack/Auxiliary.cs index ae89d710..a2b62af4 100644 --- a/src/NRedisStack/Auxiliary.cs +++ b/src/NRedisStack/Auxiliary.cs @@ -7,8 +7,8 @@ namespace NRedisStack { public static class Auxiliary { - private static bool _setInfo = false; - private static string _libraryName = ""; + private static bool _setInfo = true; + private static string? _libraryName = $"NRedisStack;.NET-{Environment.Version}"; public static List MergeArgs(RedisKey key, params RedisValue[] items) { var args = new List(items.Length + 1) { key }; @@ -34,48 +34,43 @@ public static object[] AssembleNonNullArguments(params object?[] arguments) // TODO: add all the signatures of GetDatabase public static IDatabase GetDatabase(this ConnectionMultiplexer redis, - string? LibraryName = "") + string? LibraryName) { var _db = redis.GetDatabase(); - if (LibraryName == null) - { - return _db; - } + if (LibraryName == null) // the user wants to disable the library name and version sending + _libraryName = null; - if (LibraryName != "") + else // the user set his own the library name _libraryName = $"NRedisStack({LibraryName});.NET-{Environment.Version})"; - else - _libraryName = $"NRedisStack;.NET-{Environment.Version}"; return _db; } - private static void SetInfoInPipeline(this IDatabase _db, string? LibraryName) + private static void SetInfoInPipeline(this IDatabase db) { - Pipeline pipeline = new Pipeline(_db); - _ = pipeline.Db.ClientSetInfoAsync(SetInfoAttr.LibraryName, LibraryName!); + if (_libraryName == null) return; + Pipeline pipeline = new Pipeline(db); + _ = pipeline.Db.ClientSetInfoAsync(SetInfoAttr.LibraryName, _libraryName!); _ = pipeline.Db.ClientSetInfoAsync(SetInfoAttr.LibraryVersion, GetNRedisStackVersion()!); pipeline.Execute(); } public static RedisResult Execute(this IDatabase db, SerializedCommand command) { - if(!_setInfo) + if(_setInfo) { - db.SetInfoInPipeline(_libraryName); - _setInfo = true; + db.SetInfoInPipeline(); + _setInfo = false; } return db.Execute(command.Command, command.Args); } public async static Task ExecuteAsync(this IDatabaseAsync db, SerializedCommand command) { - if(!_setInfo) + if(_setInfo) { - // TODO: check if I can do it in pipeline - _ = db.ClientSetInfoAsync(SetInfoAttr.LibraryName, _libraryName); - _ = db.ClientSetInfoAsync(SetInfoAttr.LibraryVersion, GetNRedisStackVersion()); - _setInfo = true; + ((IDatabase)db).SetInfoInPipeline(); + _setInfo = false; } return await db.ExecuteAsync(command.Command, command.Args); } From 3409bfece12842ca1017b0631a80eab05de186b5 Mon Sep 17 00:00:00 2001 From: shacharPash Date: Tue, 19 Sep 2023 17:43:58 +0300 Subject: [PATCH 14/28] change test --- .../Core Commands/CoreTests.cs | 50 +++++++++++-------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/tests/NRedisStack.Tests/Core Commands/CoreTests.cs b/tests/NRedisStack.Tests/Core Commands/CoreTests.cs index bbab7f38..2256ab8f 100644 --- a/tests/NRedisStack.Tests/Core Commands/CoreTests.cs +++ b/tests/NRedisStack.Tests/Core Commands/CoreTests.cs @@ -5,6 +5,7 @@ using StackExchange.Redis; using System.Xml.Linq; using System.Reflection; +using NRedisStack.RedisStackCommands; namespace NRedisStack.Tests.Core; @@ -14,35 +15,42 @@ public class CoreTests : AbstractNRedisStackTest, IDisposable private readonly string key = "CORE_TESTS"; public CoreTests(RedisFixture redisFixture) : base(redisFixture) { } - // [SkipIfRedis(Comparison.LessThan, "7.1.242")] - // public void TestSetInfo() - // { - // var redis = ConnectionMultiplexer.Connect("localhost"); - // var db = redis.GetDatabase("name"); // TODO: find a way that the user will not need to pass the library name and version if he wants to use the default values. + [SkipIfRedis(Comparison.LessThan, "7.1.242")] + public void TestSetInfoDefaultValue() + { + var redis = ConnectionMultiplexer.Connect("localhost"); + var db = redis.GetDatabase(); - // db.Execute("FLUSHALL"); - // var info = db.Execute("CLIENT", "INFO").ToString(); - // Assert.EndsWith($"lib-name=NRedisStack(SE.Redis-v{GetStackExchangeRedisVersion()};.NET-{Environment.Version}) lib-ver={GetNRedisStackVersion()}\n", info); + db.Execute("FLUSHALL"); + 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. - // Assert.True(db.ClientSetInfo(SetInfoAttr.LibraryName, "anylibname")); - // Assert.True(db.ClientSetInfo(SetInfoAttr.LibraryVersion, "1.2.3")); - // info = db.Execute("CLIENT", "INFO").ToString(); - // Assert.EndsWith("lib-name=anylibname lib-ver=1.2.3\n", info); - // } + var info = db.Execute("CLIENT", "INFO").ToString(); + Assert.EndsWith($"lib-name=NRedisStack;.NET-{Environment.Version} lib-ver={GetNRedisStackVersion()}\n", info); + } + + [SkipIfRedis(Comparison.LessThan, "7.1.242")] + public void TestSetInfoWithValue() + { + var redis = ConnectionMultiplexer.Connect("localhost"); + var db = redis.GetDatabase("MyLibraryName;v1.0.0"); + + db.Execute("FLUSHALL"); + 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); + } // [SkipIfRedis(Comparison.LessThan, "7.1.242")] - // public async Task TestSetInfoAsync() + // public void TestSetInfoNull() // { // var redis = ConnectionMultiplexer.Connect("localhost"); + // var db = redis.GetDatabase(null); - // var db = redis.GetDatabase(""); // TODO: find a way that the user will not need to pass the library name and version if he wants to use the default values. // db.Execute("FLUSHALL"); - // var info = (await db.ExecuteAsync("CLIENT", "INFO")).ToString(); - // Assert.EndsWith($"lib-name=NRedisStack(SE.Redis-v{GetStackExchangeRedisVersion()};.NET-{Environment.Version}) lib-ver={GetNRedisStackVersion()}\n", info); + // 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. - // Assert.True(await db.ClientSetInfoAsync(SetInfoAttr.LibraryName, "anylibname")); - // Assert.True(await db.ClientSetInfoAsync(SetInfoAttr.LibraryVersion, "1.2.3")); - // info = (await db.ExecuteAsync("CLIENT", "INFO")).ToString(); - // Assert.EndsWith("lib-name=anylibname lib-ver=1.2.3\n", info); + // var info = db.Execute("CLIENT", "INFO").ToString(); + // Assert.EndsWith($"lib-name= lib-ver=\n", info); // } } \ No newline at end of file From 62f27cf7ddc77264ebaf963047e6cc1bf8082e60 Mon Sep 17 00:00:00 2001 From: shacharPash Date: Tue, 19 Sep 2023 18:00:11 +0300 Subject: [PATCH 15/28] fix tests --- .../CoreCommands/Literals/CommandArgs.cs | 4 +-- .../Core Commands/CoreTests.cs | 26 +++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/NRedisStack/CoreCommands/Literals/CommandArgs.cs b/src/NRedisStack/CoreCommands/Literals/CommandArgs.cs index e6af3364..8d9aaf4f 100644 --- a/src/NRedisStack/CoreCommands/Literals/CommandArgs.cs +++ b/src/NRedisStack/CoreCommands/Literals/CommandArgs.cs @@ -2,7 +2,7 @@ namespace NRedisStack.Core.Literals { internal class CoreArgs { - public const string lib_name = "lib-name"; - public const string lib_ver = "lib-ver"; + public const string lib_name = "LIB-NAME"; + public const string lib_ver = "LIB-VER"; } } diff --git a/tests/NRedisStack.Tests/Core Commands/CoreTests.cs b/tests/NRedisStack.Tests/Core Commands/CoreTests.cs index 2256ab8f..cffbd8d4 100644 --- a/tests/NRedisStack.Tests/Core Commands/CoreTests.cs +++ b/tests/NRedisStack.Tests/Core Commands/CoreTests.cs @@ -28,6 +28,19 @@ public void TestSetInfoDefaultValue() Assert.EndsWith($"lib-name=NRedisStack;.NET-{Environment.Version} lib-ver={GetNRedisStackVersion()}\n", info); } + [SkipIfRedis(Comparison.LessThan, "7.1.242")] + public async Task TestSetInfoDefaultValueAsync() + { + var redis = ConnectionMultiplexer.Connect("localhost"); + var db = redis.GetDatabase(); + + db.Execute("FLUSHALL"); + 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); + } + [SkipIfRedis(Comparison.LessThan, "7.1.242")] public void TestSetInfoWithValue() { @@ -41,6 +54,19 @@ public void TestSetInfoWithValue() Assert.EndsWith($"NRedisStack(MyLibraryName;v1.0.0);.NET-{Environment.Version}) lib-ver={GetNRedisStackVersion()}\n", info); } + [SkipIfRedis(Comparison.LessThan, "7.1.242")] + public async Task TestSetInfoWithValueAsync() + { + var redis = ConnectionMultiplexer.Connect("localhost"); + var db = redis.GetDatabase("MyLibraryName;v1.0.0"); + + db.Execute("FLUSHALL"); + 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); + } + // [SkipIfRedis(Comparison.LessThan, "7.1.242")] // public void TestSetInfoNull() // { From 1122e698d5c2cdabd7fc9877dcbfb3a39af6854d Mon Sep 17 00:00:00 2001 From: shacharPash Date: Tue, 19 Sep 2023 18:08:10 +0300 Subject: [PATCH 16/28] not using pipeline --- src/NRedisStack/Auxiliary.cs | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/NRedisStack/Auxiliary.cs b/src/NRedisStack/Auxiliary.cs index a2b62af4..2c0dc823 100644 --- a/src/NRedisStack/Auxiliary.cs +++ b/src/NRedisStack/Auxiliary.cs @@ -46,20 +46,23 @@ public static IDatabase GetDatabase(this ConnectionMultiplexer redis, return _db; } - private static void SetInfoInPipeline(this IDatabase db) - { - if (_libraryName == null) return; - Pipeline pipeline = new Pipeline(db); - _ = pipeline.Db.ClientSetInfoAsync(SetInfoAttr.LibraryName, _libraryName!); - _ = pipeline.Db.ClientSetInfoAsync(SetInfoAttr.LibraryVersion, GetNRedisStackVersion()!); - pipeline.Execute(); - } + // TODO: understand why this method is not working: + // private static void SetInfoInPipeline(this IDatabase db) + // { + // if (_libraryName == null) return; + // Pipeline pipeline = new Pipeline(db); + // _ = pipeline.Db.ClientSetInfoAsync(SetInfoAttr.LibraryName, _libraryName!); + // _ = pipeline.Db.ClientSetInfoAsync(SetInfoAttr.LibraryVersion, GetNRedisStackVersion()); + // pipeline.Execute(); + // } public static RedisResult Execute(this IDatabase db, SerializedCommand command) { if(_setInfo) { - db.SetInfoInPipeline(); + // db.SetInfoInPipeline(); + db.ClientSetInfo(SetInfoAttr.LibraryName, _libraryName!); + db.ClientSetInfo(SetInfoAttr.LibraryVersion, GetNRedisStackVersion()); _setInfo = false; } return db.Execute(command.Command, command.Args); @@ -69,7 +72,9 @@ public async static Task ExecuteAsync(this IDatabaseAsync db, Seria { if(_setInfo) { - ((IDatabase)db).SetInfoInPipeline(); + // ((IDatabase)db).SetInfoInPipeline(); + await db.ClientSetInfoAsync(SetInfoAttr.LibraryName, _libraryName!); + await db.ClientSetInfoAsync(SetInfoAttr.LibraryVersion, GetNRedisStackVersion()); _setInfo = false; } return await db.ExecuteAsync(command.Command, command.Args); From 8739251c63a186b5893625a7bc98ecab4f296a53 Mon Sep 17 00:00:00 2001 From: shacharPash Date: Tue, 19 Sep 2023 18:14:57 +0300 Subject: [PATCH 17/28] move _setInfo = false; --- src/NRedisStack/Auxiliary.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/NRedisStack/Auxiliary.cs b/src/NRedisStack/Auxiliary.cs index 2c0dc823..8885e7a9 100644 --- a/src/NRedisStack/Auxiliary.cs +++ b/src/NRedisStack/Auxiliary.cs @@ -60,10 +60,10 @@ public static RedisResult Execute(this IDatabase db, SerializedCommand command) { if(_setInfo) { + _setInfo = false; // db.SetInfoInPipeline(); db.ClientSetInfo(SetInfoAttr.LibraryName, _libraryName!); db.ClientSetInfo(SetInfoAttr.LibraryVersion, GetNRedisStackVersion()); - _setInfo = false; } return db.Execute(command.Command, command.Args); } @@ -72,10 +72,10 @@ public async static Task ExecuteAsync(this IDatabaseAsync db, Seria { if(_setInfo) { + _setInfo = false; // ((IDatabase)db).SetInfoInPipeline(); await db.ClientSetInfoAsync(SetInfoAttr.LibraryName, _libraryName!); await db.ClientSetInfoAsync(SetInfoAttr.LibraryVersion, GetNRedisStackVersion()); - _setInfo = false; } return await db.ExecuteAsync(command.Command, command.Args); } From 36749d7fc4049710958db694dc35eef4a53d2146 Mon Sep 17 00:00:00 2001 From: shacharPash Date: Wed, 20 Sep 2023 12:51:48 +0300 Subject: [PATCH 18/28] delete unused key --- tests/NRedisStack.Tests/Core Commands/CoreTests.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/NRedisStack.Tests/Core Commands/CoreTests.cs b/tests/NRedisStack.Tests/Core Commands/CoreTests.cs index cffbd8d4..9573f592 100644 --- a/tests/NRedisStack.Tests/Core Commands/CoreTests.cs +++ b/tests/NRedisStack.Tests/Core Commands/CoreTests.cs @@ -12,7 +12,6 @@ namespace NRedisStack.Tests.Core; public class CoreTests : AbstractNRedisStackTest, IDisposable { - private readonly string key = "CORE_TESTS"; public CoreTests(RedisFixture redisFixture) : base(redisFixture) { } [SkipIfRedis(Comparison.LessThan, "7.1.242")] From 3822d06e55cd9cb16885e69f0d5ffa27ec013db3 Mon Sep 17 00:00:00 2001 From: shacharPash Date: Wed, 20 Sep 2023 14:28:32 +0300 Subject: [PATCH 19/28] if redis version less than 7.1.242 dont sent SETINFO --- src/NRedisStack/Auxiliary.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/NRedisStack/Auxiliary.cs b/src/NRedisStack/Auxiliary.cs index 8885e7a9..da810124 100644 --- a/src/NRedisStack/Auxiliary.cs +++ b/src/NRedisStack/Auxiliary.cs @@ -58,7 +58,8 @@ public static IDatabase GetDatabase(this ConnectionMultiplexer redis, public static RedisResult Execute(this IDatabase db, SerializedCommand command) { - if(_setInfo) + var compareVersions = db.Multiplexer.GetServer(db.Multiplexer.GetEndPoints()[0]).Version.CompareTo(new Version(7, 1, 242)); + if (_setInfo && compareVersions >= 0) { _setInfo = false; // db.SetInfoInPipeline(); @@ -70,7 +71,8 @@ public static RedisResult Execute(this IDatabase db, SerializedCommand command) public async static Task ExecuteAsync(this IDatabaseAsync db, SerializedCommand command) { - if(_setInfo) + var compareVersions = db.Multiplexer.GetServer(db.Multiplexer.GetEndPoints()[0]).Version.CompareTo(new Version(7, 1, 242)); + if (_setInfo && compareVersions >= 0) { _setInfo = false; // ((IDatabase)db).SetInfoInPipeline(); From fce926f3289fd4d53687265157296cfc1cdfe0e6 Mon Sep 17 00:00:00 2001 From: shacharPash Date: Wed, 20 Sep 2023 16:09:38 +0300 Subject: [PATCH 20/28] add sleep --- tests/NRedisStack.Tests/Core Commands/CoreTests.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/NRedisStack.Tests/Core Commands/CoreTests.cs b/tests/NRedisStack.Tests/Core Commands/CoreTests.cs index 9573f592..686f8970 100644 --- a/tests/NRedisStack.Tests/Core Commands/CoreTests.cs +++ b/tests/NRedisStack.Tests/Core Commands/CoreTests.cs @@ -22,6 +22,8 @@ public void TestSetInfoDefaultValue() db.Execute("FLUSHALL"); 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. + // sleep for 1 second to make sure that the PING command is executed before the CLIENT INFO command. + Thread.Sleep(1000); var info = db.Execute("CLIENT", "INFO").ToString(); Assert.EndsWith($"lib-name=NRedisStack;.NET-{Environment.Version} lib-ver={GetNRedisStackVersion()}\n", info); @@ -35,6 +37,8 @@ public async Task TestSetInfoDefaultValueAsync() db.Execute("FLUSHALL"); 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. + // sleep for 1 second to make sure that the PING command is executed before the CLIENT INFO command. + Thread.Sleep(1000); var info = (await db.ExecuteAsync("CLIENT", "INFO")).ToString(); Assert.EndsWith($"lib-name=NRedisStack;.NET-{Environment.Version} lib-ver={GetNRedisStackVersion()}\n", info); @@ -48,6 +52,8 @@ public void TestSetInfoWithValue() db.Execute("FLUSHALL"); 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. + // sleep for 1 second to make sure that the PING command is executed before the CLIENT INFO command. + Thread.Sleep(1000); var info = db.Execute("CLIENT", "INFO").ToString(); Assert.EndsWith($"NRedisStack(MyLibraryName;v1.0.0);.NET-{Environment.Version}) lib-ver={GetNRedisStackVersion()}\n", info); @@ -61,7 +67,9 @@ public async Task TestSetInfoWithValueAsync() db.Execute("FLUSHALL"); 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. - + // sleep for 1 second to make sure that the PING command is executed before the CLIENT INFO command. + Thread.Sleep(1000); + var info = (await db.ExecuteAsync("CLIENT", "INFO")).ToString(); Assert.EndsWith($"NRedisStack(MyLibraryName;v1.0.0);.NET-{Environment.Version}) lib-ver={GetNRedisStackVersion()}\n", info); } From 08b89c6f2cc8b8254193afa093a8f7ddcfe24915 Mon Sep 17 00:00:00 2001 From: shacharPash Date: Thu, 21 Sep 2023 15:05:22 +0300 Subject: [PATCH 21/28] no sleep --- tests/NRedisStack.Tests/Core Commands/CoreTests.cs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/tests/NRedisStack.Tests/Core Commands/CoreTests.cs b/tests/NRedisStack.Tests/Core Commands/CoreTests.cs index 686f8970..9573f592 100644 --- a/tests/NRedisStack.Tests/Core Commands/CoreTests.cs +++ b/tests/NRedisStack.Tests/Core Commands/CoreTests.cs @@ -22,8 +22,6 @@ public void TestSetInfoDefaultValue() db.Execute("FLUSHALL"); 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. - // sleep for 1 second to make sure that the PING command is executed before the CLIENT INFO command. - Thread.Sleep(1000); var info = db.Execute("CLIENT", "INFO").ToString(); Assert.EndsWith($"lib-name=NRedisStack;.NET-{Environment.Version} lib-ver={GetNRedisStackVersion()}\n", info); @@ -37,8 +35,6 @@ public async Task TestSetInfoDefaultValueAsync() db.Execute("FLUSHALL"); 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. - // sleep for 1 second to make sure that the PING command is executed before the CLIENT INFO command. - Thread.Sleep(1000); var info = (await db.ExecuteAsync("CLIENT", "INFO")).ToString(); Assert.EndsWith($"lib-name=NRedisStack;.NET-{Environment.Version} lib-ver={GetNRedisStackVersion()}\n", info); @@ -52,8 +48,6 @@ public void TestSetInfoWithValue() db.Execute("FLUSHALL"); 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. - // sleep for 1 second to make sure that the PING command is executed before the CLIENT INFO command. - Thread.Sleep(1000); var info = db.Execute("CLIENT", "INFO").ToString(); Assert.EndsWith($"NRedisStack(MyLibraryName;v1.0.0);.NET-{Environment.Version}) lib-ver={GetNRedisStackVersion()}\n", info); @@ -67,9 +61,7 @@ public async Task TestSetInfoWithValueAsync() db.Execute("FLUSHALL"); 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. - // sleep for 1 second to make sure that the PING command is executed before the CLIENT INFO command. - Thread.Sleep(1000); - + var info = (await db.ExecuteAsync("CLIENT", "INFO")).ToString(); Assert.EndsWith($"NRedisStack(MyLibraryName;v1.0.0);.NET-{Environment.Version}) lib-ver={GetNRedisStackVersion()}\n", info); } From f72b28d99a96f4475fa32c7bb780851bcd600b3e Mon Sep 17 00:00:00 2001 From: shacharPash Date: Wed, 18 Oct 2023 15:02:39 +0300 Subject: [PATCH 22/28] try setinfo to true in each test --- src/NRedisStack/Auxiliary.cs | 3 ++- tests/NRedisStack.Tests/Core Commands/CoreTests.cs | 12 ++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/NRedisStack/Auxiliary.cs b/src/NRedisStack/Auxiliary.cs index da810124..32eae617 100644 --- a/src/NRedisStack/Auxiliary.cs +++ b/src/NRedisStack/Auxiliary.cs @@ -7,8 +7,9 @@ namespace NRedisStack { public static class Auxiliary { - private static bool _setInfo = true; private static string? _libraryName = $"NRedisStack;.NET-{Environment.Version}"; + private static bool _setInfo = true; + public static void SetInfoTrue() => _setInfo = true; public static List MergeArgs(RedisKey key, params RedisValue[] items) { var args = new List(items.Length + 1) { key }; diff --git a/tests/NRedisStack.Tests/Core Commands/CoreTests.cs b/tests/NRedisStack.Tests/Core Commands/CoreTests.cs index 9573f592..981586f6 100644 --- a/tests/NRedisStack.Tests/Core Commands/CoreTests.cs +++ b/tests/NRedisStack.Tests/Core Commands/CoreTests.cs @@ -19,8 +19,9 @@ public void TestSetInfoDefaultValue() { var redis = ConnectionMultiplexer.Connect("localhost"); var db = redis.GetDatabase(); - db.Execute("FLUSHALL"); + SetInfoTrue(); // demonstrate first connection + 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(); @@ -32,8 +33,9 @@ public async Task TestSetInfoDefaultValueAsync() { var redis = ConnectionMultiplexer.Connect("localhost"); var db = redis.GetDatabase(); - db.Execute("FLUSHALL"); + SetInfoTrue(); // demonstrate first connection + 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(); @@ -45,8 +47,9 @@ public void TestSetInfoWithValue() { var redis = ConnectionMultiplexer.Connect("localhost"); var db = redis.GetDatabase("MyLibraryName;v1.0.0"); - db.Execute("FLUSHALL"); + SetInfoTrue(); // demonstrate first connection + 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(); @@ -58,8 +61,9 @@ public async Task TestSetInfoWithValueAsync() { var redis = ConnectionMultiplexer.Connect("localhost"); var db = redis.GetDatabase("MyLibraryName;v1.0.0"); - db.Execute("FLUSHALL"); + SetInfoTrue(); // demonstrate first connection + 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(); From 1c4dd72200f261a7b766346d942aa77f6c5883d0 Mon Sep 17 00:00:00 2001 From: shacharPash Date: Wed, 18 Oct 2023 15:30:11 +0300 Subject: [PATCH 23/28] reset info defaults in each test --- src/NRedisStack/Auxiliary.cs | 6 +++++- tests/NRedisStack.Tests/Core Commands/CoreTests.cs | 8 ++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/NRedisStack/Auxiliary.cs b/src/NRedisStack/Auxiliary.cs index 32eae617..cbdcbfc2 100644 --- a/src/NRedisStack/Auxiliary.cs +++ b/src/NRedisStack/Auxiliary.cs @@ -9,7 +9,11 @@ public static class Auxiliary { private static string? _libraryName = $"NRedisStack;.NET-{Environment.Version}"; private static bool _setInfo = true; - public static void SetInfoTrue() => _setInfo = true; + public static void ResetInfoDefaults() + { + _setInfo = true; + _libraryName = $"NRedisStack;.NET-{Environment.Version}"; + } public static List MergeArgs(RedisKey key, params RedisValue[] items) { var args = new List(items.Length + 1) { key }; diff --git a/tests/NRedisStack.Tests/Core Commands/CoreTests.cs b/tests/NRedisStack.Tests/Core Commands/CoreTests.cs index 981586f6..f5d60367 100644 --- a/tests/NRedisStack.Tests/Core Commands/CoreTests.cs +++ b/tests/NRedisStack.Tests/Core Commands/CoreTests.cs @@ -17,10 +17,10 @@ public CoreTests(RedisFixture redisFixture) : base(redisFixture) { } [SkipIfRedis(Comparison.LessThan, "7.1.242")] public void TestSetInfoDefaultValue() { + ResetInfoDefaults(); // demonstrate first connection var redis = ConnectionMultiplexer.Connect("localhost"); var db = redis.GetDatabase(); db.Execute("FLUSHALL"); - SetInfoTrue(); // demonstrate first connection 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. @@ -31,10 +31,10 @@ public void TestSetInfoDefaultValue() [SkipIfRedis(Comparison.LessThan, "7.1.242")] public async Task TestSetInfoDefaultValueAsync() { + ResetInfoDefaults(); // demonstrate first connection var redis = ConnectionMultiplexer.Connect("localhost"); var db = redis.GetDatabase(); db.Execute("FLUSHALL"); - SetInfoTrue(); // demonstrate first connection 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. @@ -45,10 +45,10 @@ public async Task TestSetInfoDefaultValueAsync() [SkipIfRedis(Comparison.LessThan, "7.1.242")] public void TestSetInfoWithValue() { + ResetInfoDefaults(); // demonstrate first connection var redis = ConnectionMultiplexer.Connect("localhost"); var db = redis.GetDatabase("MyLibraryName;v1.0.0"); db.Execute("FLUSHALL"); - SetInfoTrue(); // demonstrate first connection 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. @@ -59,10 +59,10 @@ public void TestSetInfoWithValue() [SkipIfRedis(Comparison.LessThan, "7.1.242")] public async Task TestSetInfoWithValueAsync() { + ResetInfoDefaults(); // demonstrate first connection var redis = ConnectionMultiplexer.Connect("localhost"); var db = redis.GetDatabase("MyLibraryName;v1.0.0"); db.Execute("FLUSHALL"); - SetInfoTrue(); // demonstrate first connection 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. From 1bca6574858dc9cc9666e19d5f5d277cd862c4a7 Mon Sep 17 00:00:00 2001 From: shacharPash Date: Wed, 18 Oct 2023 15:36:53 +0300 Subject: [PATCH 24/28] skip cluster + send commands in pipeline --- src/NRedisStack/Auxiliary.cs | 28 +++++++++---------- .../Core Commands/CoreTests.cs | 10 +++---- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/NRedisStack/Auxiliary.cs b/src/NRedisStack/Auxiliary.cs index cbdcbfc2..7e602508 100644 --- a/src/NRedisStack/Auxiliary.cs +++ b/src/NRedisStack/Auxiliary.cs @@ -52,14 +52,14 @@ public static IDatabase GetDatabase(this ConnectionMultiplexer redis, } // TODO: understand why this method is not working: - // private static void SetInfoInPipeline(this IDatabase db) - // { - // if (_libraryName == null) return; - // Pipeline pipeline = new Pipeline(db); - // _ = pipeline.Db.ClientSetInfoAsync(SetInfoAttr.LibraryName, _libraryName!); - // _ = pipeline.Db.ClientSetInfoAsync(SetInfoAttr.LibraryVersion, GetNRedisStackVersion()); - // pipeline.Execute(); - // } + private static void SetInfoInPipeline(this IDatabase db) + { + if (_libraryName == null) return; + Pipeline pipeline = new Pipeline(db); + _ = pipeline.Db.ClientSetInfoAsync(SetInfoAttr.LibraryName, _libraryName!); + _ = pipeline.Db.ClientSetInfoAsync(SetInfoAttr.LibraryVersion, GetNRedisStackVersion()); + pipeline.Execute(); + } public static RedisResult Execute(this IDatabase db, SerializedCommand command) { @@ -67,9 +67,9 @@ public static RedisResult Execute(this IDatabase db, SerializedCommand command) if (_setInfo && compareVersions >= 0) { _setInfo = false; - // db.SetInfoInPipeline(); - db.ClientSetInfo(SetInfoAttr.LibraryName, _libraryName!); - db.ClientSetInfo(SetInfoAttr.LibraryVersion, GetNRedisStackVersion()); + db.SetInfoInPipeline(); + // db.ClientSetInfo(SetInfoAttr.LibraryName, _libraryName!); + // db.ClientSetInfo(SetInfoAttr.LibraryVersion, GetNRedisStackVersion()); } return db.Execute(command.Command, command.Args); } @@ -80,9 +80,9 @@ public async static Task ExecuteAsync(this IDatabaseAsync db, Seria if (_setInfo && compareVersions >= 0) { _setInfo = false; - // ((IDatabase)db).SetInfoInPipeline(); - await db.ClientSetInfoAsync(SetInfoAttr.LibraryName, _libraryName!); - await db.ClientSetInfoAsync(SetInfoAttr.LibraryVersion, GetNRedisStackVersion()); + ((IDatabase)db).SetInfoInPipeline(); + // await db.ClientSetInfoAsync(SetInfoAttr.LibraryName, _libraryName!); + // await db.ClientSetInfoAsync(SetInfoAttr.LibraryVersion, GetNRedisStackVersion()); } return await db.ExecuteAsync(command.Command, command.Args); } diff --git a/tests/NRedisStack.Tests/Core Commands/CoreTests.cs b/tests/NRedisStack.Tests/Core Commands/CoreTests.cs index f5d60367..7ed66550 100644 --- a/tests/NRedisStack.Tests/Core Commands/CoreTests.cs +++ b/tests/NRedisStack.Tests/Core Commands/CoreTests.cs @@ -14,7 +14,7 @@ public class CoreTests : AbstractNRedisStackTest, IDisposable { public CoreTests(RedisFixture redisFixture) : base(redisFixture) { } - [SkipIfRedis(Comparison.LessThan, "7.1.242")] + [SkipIfRedis(Is.OSSCluster, Comparison.LessThan, "7.1.242")] public void TestSetInfoDefaultValue() { ResetInfoDefaults(); // demonstrate first connection @@ -28,7 +28,7 @@ public void TestSetInfoDefaultValue() Assert.EndsWith($"lib-name=NRedisStack;.NET-{Environment.Version} lib-ver={GetNRedisStackVersion()}\n", info); } - [SkipIfRedis(Comparison.LessThan, "7.1.242")] + [SkipIfRedis(Is.OSSCluster, Comparison.LessThan, "7.1.242")] public async Task TestSetInfoDefaultValueAsync() { ResetInfoDefaults(); // demonstrate first connection @@ -42,7 +42,7 @@ public async Task TestSetInfoDefaultValueAsync() Assert.EndsWith($"lib-name=NRedisStack;.NET-{Environment.Version} lib-ver={GetNRedisStackVersion()}\n", info); } - [SkipIfRedis(Comparison.LessThan, "7.1.242")] + [SkipIfRedis(Is.OSSCluster, Comparison.LessThan, "7.1.242")] public void TestSetInfoWithValue() { ResetInfoDefaults(); // demonstrate first connection @@ -56,7 +56,7 @@ public void TestSetInfoWithValue() Assert.EndsWith($"NRedisStack(MyLibraryName;v1.0.0);.NET-{Environment.Version}) lib-ver={GetNRedisStackVersion()}\n", info); } - [SkipIfRedis(Comparison.LessThan, "7.1.242")] + [SkipIfRedis(Is.OSSCluster, Comparison.LessThan, "7.1.242")] public async Task TestSetInfoWithValueAsync() { ResetInfoDefaults(); // demonstrate first connection @@ -70,7 +70,7 @@ public async Task TestSetInfoWithValueAsync() Assert.EndsWith($"NRedisStack(MyLibraryName;v1.0.0);.NET-{Environment.Version}) lib-ver={GetNRedisStackVersion()}\n", info); } - // [SkipIfRedis(Comparison.LessThan, "7.1.242")] + // [SkipIfRedis(Is.OSSCluster, Comparison.LessThan, "7.1.242")] // public void TestSetInfoNull() // { // var redis = ConnectionMultiplexer.Connect("localhost"); From ba79c14f338b94a6aac2a5bb0403d25f9ebbf035 Mon Sep 17 00:00:00 2001 From: shacharPash Date: Wed, 18 Oct 2023 15:37:17 +0300 Subject: [PATCH 25/28] delete comments --- src/NRedisStack/Auxiliary.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/NRedisStack/Auxiliary.cs b/src/NRedisStack/Auxiliary.cs index 7e602508..c984f743 100644 --- a/src/NRedisStack/Auxiliary.cs +++ b/src/NRedisStack/Auxiliary.cs @@ -68,8 +68,6 @@ public static RedisResult Execute(this IDatabase db, SerializedCommand command) { _setInfo = false; db.SetInfoInPipeline(); - // db.ClientSetInfo(SetInfoAttr.LibraryName, _libraryName!); - // db.ClientSetInfo(SetInfoAttr.LibraryVersion, GetNRedisStackVersion()); } return db.Execute(command.Command, command.Args); } @@ -81,8 +79,6 @@ public async static Task ExecuteAsync(this IDatabaseAsync db, Seria { _setInfo = false; ((IDatabase)db).SetInfoInPipeline(); - // await db.ClientSetInfoAsync(SetInfoAttr.LibraryName, _libraryName!); - // await db.ClientSetInfoAsync(SetInfoAttr.LibraryVersion, GetNRedisStackVersion()); } return await db.ExecuteAsync(command.Command, command.Args); } From 3f548d58c727f5dfa68b7144bc647ab7bc1a8a9d Mon Sep 17 00:00:00 2001 From: shacharPash Date: Wed, 18 Oct 2023 15:48:31 +0300 Subject: [PATCH 26/28] add null test --- src/NRedisStack/Auxiliary.cs | 3 +- .../Core Commands/CoreTests.cs | 41 +++++++++++++------ 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/src/NRedisStack/Auxiliary.cs b/src/NRedisStack/Auxiliary.cs index c984f743..00ad672c 100644 --- a/src/NRedisStack/Auxiliary.cs +++ b/src/NRedisStack/Auxiliary.cs @@ -43,7 +43,7 @@ public static IDatabase GetDatabase(this ConnectionMultiplexer redis, { var _db = redis.GetDatabase(); if (LibraryName == null) // the user wants to disable the library name and version sending - _libraryName = null; + _setInfo = false; else // the user set his own the library name _libraryName = $"NRedisStack({LibraryName});.NET-{Environment.Version})"; @@ -51,7 +51,6 @@ public static IDatabase GetDatabase(this ConnectionMultiplexer redis, return _db; } - // TODO: understand why this method is not working: private static void SetInfoInPipeline(this IDatabase db) { if (_libraryName == null) return; diff --git a/tests/NRedisStack.Tests/Core Commands/CoreTests.cs b/tests/NRedisStack.Tests/Core Commands/CoreTests.cs index 7ed66550..08ede3be 100644 --- a/tests/NRedisStack.Tests/Core Commands/CoreTests.cs +++ b/tests/NRedisStack.Tests/Core Commands/CoreTests.cs @@ -70,16 +70,33 @@ public async Task TestSetInfoWithValueAsync() Assert.EndsWith($"NRedisStack(MyLibraryName;v1.0.0);.NET-{Environment.Version}) lib-ver={GetNRedisStackVersion()}\n", info); } - // [SkipIfRedis(Is.OSSCluster, Comparison.LessThan, "7.1.242")] - // public void TestSetInfoNull() - // { - // var redis = ConnectionMultiplexer.Connect("localhost"); - // var db = redis.GetDatabase(null); - - // db.Execute("FLUSHALL"); - // 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= lib-ver=\n", info); - // } + [SkipIfRedis(Is.OSSCluster, Comparison.LessThan, "7.1.242")] + public void TestSetInfoNull() + { + ResetInfoDefaults(); // demonstrate first connection + var redis = ConnectionMultiplexer.Connect("localhost"); + var db = redis.GetDatabase(null); + + db.Execute("FLUSHALL"); + var infoBefore = db.Execute("CLIENT", "INFO").ToString(); + 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 infoAfter = db.Execute("CLIENT", "INFO").ToString(); + Assert.EndsWith(infoAfter, infoBefore); + } + + [SkipIfRedis(Is.OSSCluster, Comparison.LessThan, "7.1.242")] + public async Task TestSetInfoNullAsync() + { + ResetInfoDefaults(); // demonstrate first connection + var redis = ConnectionMultiplexer.Connect("localhost"); + var db = redis.GetDatabase(null); + + db.Execute("FLUSHALL"); + var infoBefore = (await db.ExecuteAsync("CLIENT", "INFO")).ToString(); + 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 infoAfter = (await db.ExecuteAsync("CLIENT", "INFO")).ToString(); + Assert.EndsWith(infoAfter, infoBefore); + } } \ No newline at end of file From 68b6f5f210bf5a7cabf8dc7e80828789a5df05d7 Mon Sep 17 00:00:00 2001 From: shacharPash Date: Wed, 18 Oct 2023 16:14:24 +0300 Subject: [PATCH 27/28] compare and of strings in null test --- .../Core Commands/CoreTests.cs | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/tests/NRedisStack.Tests/Core Commands/CoreTests.cs b/tests/NRedisStack.Tests/Core Commands/CoreTests.cs index 08ede3be..d94e2f87 100644 --- a/tests/NRedisStack.Tests/Core Commands/CoreTests.cs +++ b/tests/NRedisStack.Tests/Core Commands/CoreTests.cs @@ -82,7 +82,16 @@ public void TestSetInfoNull() 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 infoAfter = db.Execute("CLIENT", "INFO").ToString(); - Assert.EndsWith(infoAfter, infoBefore); + // Find the indices of "lib-name=" in the strings + int infoAfterLibNameIndex = infoAfter!.IndexOf("lib-name="); + int infoBeforeLibNameIndex = infoBefore!.IndexOf("lib-name="); + + // Extract the sub-strings starting from "lib-name=" + string infoAfterLibNameToEnd = infoAfter.Substring(infoAfterLibNameIndex); + string infoBeforeLibNameToEnd = infoBefore.Substring(infoBeforeLibNameIndex); + + // Assert that the extracted sub-strings are equal + Assert.Equal(infoAfterLibNameToEnd, infoBeforeLibNameToEnd); } [SkipIfRedis(Is.OSSCluster, Comparison.LessThan, "7.1.242")] @@ -97,6 +106,15 @@ public async Task TestSetInfoNullAsync() 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 infoAfter = (await db.ExecuteAsync("CLIENT", "INFO")).ToString(); - Assert.EndsWith(infoAfter, infoBefore); + // Find the indices of "lib-name=" in the strings + int infoAfterLibNameIndex = infoAfter!.IndexOf("lib-name="); + int infoBeforeLibNameIndex = infoBefore!.IndexOf("lib-name="); + + // Extract the sub-strings starting from "lib-name=" + string infoAfterLibNameToEnd = infoAfter.Substring(infoAfterLibNameIndex); + string infoBeforeLibNameToEnd = infoBefore.Substring(infoBeforeLibNameIndex); + + // Assert that the extracted sub-strings are equal + Assert.Equal(infoAfterLibNameToEnd, infoBeforeLibNameToEnd); } } \ No newline at end of file From 28bc9e070538349db8d57570e7c38fdb28846880 Mon Sep 17 00:00:00 2001 From: shacharPash Date: Thu, 19 Oct 2023 12:28:30 +0300 Subject: [PATCH 28/28] fixes --- src/NRedisStack/Auxiliary.cs | 16 +--------- src/NRedisStack/CoreCommands/CoreCommands.cs | 2 -- .../Core Commands/CoreTests.cs | 29 +++++++++++++++++++ 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/src/NRedisStack/Auxiliary.cs b/src/NRedisStack/Auxiliary.cs index 00ad672c..207f39ac 100644 --- a/src/NRedisStack/Auxiliary.cs +++ b/src/NRedisStack/Auxiliary.cs @@ -8,7 +8,7 @@ namespace NRedisStack public static class Auxiliary { private static string? _libraryName = $"NRedisStack;.NET-{Environment.Version}"; - private static bool _setInfo = true; + private static bool _setInfo = true; public static void ResetInfoDefaults() { _setInfo = true; @@ -142,20 +142,6 @@ public static string GetNRedisStackVersion() return versionElement!.Value; } - public static string GetStackExchangeRedisVersion() - { - XDocument csprojDocument = GetCsprojDocument(); - - // Find the PackageReference element with Include="StackExchange.Redis" and get its Version attribute. - var stackExchangeRedisVersion = csprojDocument.Root! - .Descendants("PackageReference") - .Where(element => element.Attribute("Include")?.Value == "StackExchange.Redis") - .Select(element => element.Attribute("Version")?.Value) - .FirstOrDefault(); - - return stackExchangeRedisVersion!; - } - private static XDocument GetCsprojDocument() { string csprojFilePath = Path.Combine(Directory.GetCurrentDirectory(), "..", "..", "..", "..", "..", "src", "NRedisStack", "NRedisStack.csproj"); diff --git a/src/NRedisStack/CoreCommands/CoreCommands.cs b/src/NRedisStack/CoreCommands/CoreCommands.cs index a3312d8e..0040c2bc 100644 --- a/src/NRedisStack/CoreCommands/CoreCommands.cs +++ b/src/NRedisStack/CoreCommands/CoreCommands.cs @@ -1,5 +1,4 @@ using NRedisStack.Core; -using NRedisStack.Core.Literals; using StackExchange.Redis; namespace NRedisStack { @@ -15,7 +14,6 @@ public static class CoreCommands /// public static bool ClientSetInfo(this IDatabase db, SetInfoAttr attr, string value) { - return db.Execute(CoreCommandBuilder.ClientSetInfo(attr, value)).OKtoBoolean(); } } diff --git a/tests/NRedisStack.Tests/Core Commands/CoreTests.cs b/tests/NRedisStack.Tests/Core Commands/CoreTests.cs index d94e2f87..d403dec2 100644 --- a/tests/NRedisStack.Tests/Core Commands/CoreTests.cs +++ b/tests/NRedisStack.Tests/Core Commands/CoreTests.cs @@ -14,6 +14,35 @@ public class CoreTests : AbstractNRedisStackTest, IDisposable { public CoreTests(RedisFixture redisFixture) : base(redisFixture) { } + + [SkipIfRedis(Is.OSSCluster, Comparison.LessThan, "7.1.242")] + public void TestSimpleSetInfo() + { + var redis = ConnectionMultiplexer.Connect("localhost"); + var db = redis.GetDatabase(); + db.Execute("FLUSHALL"); + + db.ClientSetInfo(SetInfoAttr.LibraryName, "TestLibraryName"); + db.ClientSetInfo(SetInfoAttr.LibraryVersion, "1.2.3"); + + var info = db.Execute("CLIENT", "INFO").ToString(); + Assert.EndsWith($"lib-name=TestLibraryName lib-ver=1.2.3\n", info); + } + + [SkipIfRedis(Is.OSSCluster, Comparison.LessThan, "7.1.242")] + public async Task TestSimpleSetInfoAsync() + { + var redis = ConnectionMultiplexer.Connect("localhost"); + var db = redis.GetDatabase(); + db.Execute("FLUSHALL"); + + await db.ClientSetInfoAsync(SetInfoAttr.LibraryName, "TestLibraryName"); + await db.ClientSetInfoAsync(SetInfoAttr.LibraryVersion, "1.2.3"); + + var info = db.Execute("CLIENT", "INFO").ToString(); + Assert.EndsWith($"lib-name=TestLibraryName lib-ver=1.2.3\n", info); + } + [SkipIfRedis(Is.OSSCluster, Comparison.LessThan, "7.1.242")] public void TestSetInfoDefaultValue() {