From ba2070c93e0a4b2ba09d61469c8bd408801d39c4 Mon Sep 17 00:00:00 2001 From: Andy Stark Date: Fri, 27 Jun 2025 13:06:32 +0100 Subject: [PATCH 1/3] DOC-4493 added set command examples --- tests/Doc/CmdsSetExample copy.cs | 71 ++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 tests/Doc/CmdsSetExample copy.cs diff --git a/tests/Doc/CmdsSetExample copy.cs b/tests/Doc/CmdsSetExample copy.cs new file mode 100644 index 00000000..2916aeda --- /dev/null +++ b/tests/Doc/CmdsSetExample copy.cs @@ -0,0 +1,71 @@ +// EXAMPLE: cmds_set +using StackExchange.Redis; +// REMOVE_START +using NRedisStack.Tests; +namespace Doc; + +[Collection("DocsTests")] +// REMOVE_END + +public class CmdsSetExample +// REMOVE_START +: AbstractNRedisStackTest, IDisposable +// REMOVE_END +{ + // REMOVE_START + public CmdsSetExample(EndpointsFixture fixture) : base(fixture) { } + + [SkippableFact] + // REMOVE_END + public void run() + { + // REMOVE_START + // This is needed because we're constructing ConfigurationOptions in the test before calling GetConnection + SkipIfTargetConnectionDoesNotExist(EndpointsFixture.Env.Standalone); + var _ = GetCleanDatabase(EndpointsFixture.Env.Standalone); + // REMOVE_END + var muxer = ConnectionMultiplexer.Connect("localhost:6379"); + var db = muxer.GetDatabase(); + // REMOVE_START + // Clear any keys here before using them in tests. + db.KeyDelete("myset"); + // REMOVE_END + + // STEP_START sadd + bool sAddResult1 = db.SetAdd("myset", "Hello"); + Console.WriteLine(sAddResult1); // >>> True + + bool sAddResult2 = db.SetAdd("myset", "World"); + Console.WriteLine(sAddResult2); // >>> True + + bool sAddResult3 = db.SetAdd("myset", "World"); + Console.WriteLine(sAddResult2); // >>> False + + RedisValue[] sAddResult4 = db.SetMembers("myset"); + Console.WriteLine(string.Join(", ", sAddResult4)); + // >>> Hello, World + // STEP_END + // REMOVE_START + Assert.True(sAddResult1); + Assert.True(sAddResult2); + Assert.False(sAddResult3); + Assert.Equal("Hello, World", string.Join(", ", sAddResult4)); + db.KeyDelete("myset"); + // REMOVE_END + + // STEP_START smembers + long sMembersResult1 = db.SetAdd( + "myset", new RedisValue[] { "Hello", "World" } + ); + Console.WriteLine(sMembersResult1); // >>> 2 + + RedisValue[] sMembersResult2 = db.SetMembers("myset"); + Console.WriteLine(string.Join(", ", sMembersResult2)); + // >>> Hello, World + // STEP_END + // REMOVE_START + Assert.Equal(2, sMembersResult1); + Assert.Equal("Hello, World", string.Join(", ", sMembersResult2)); + // REMOVE_END + } +} From 8e3935c58d73f3893b2ba89d22f34bb720d0b14b Mon Sep 17 00:00:00 2001 From: Andy Stark Date: Fri, 27 Jun 2025 13:34:08 +0100 Subject: [PATCH 2/3] DOC-4493 fixed nondeterministic test and renamed file --- tests/Doc/{CmdsSetExample copy.cs => CmdsSetExample.cs} | 1 + 1 file changed, 1 insertion(+) rename tests/Doc/{CmdsSetExample copy.cs => CmdsSetExample.cs} (98%) diff --git a/tests/Doc/CmdsSetExample copy.cs b/tests/Doc/CmdsSetExample.cs similarity index 98% rename from tests/Doc/CmdsSetExample copy.cs rename to tests/Doc/CmdsSetExample.cs index 2916aeda..f1eb69d4 100644 --- a/tests/Doc/CmdsSetExample copy.cs +++ b/tests/Doc/CmdsSetExample.cs @@ -60,6 +60,7 @@ public void run() Console.WriteLine(sMembersResult1); // >>> 2 RedisValue[] sMembersResult2 = db.SetMembers("myset"); + Array.Sort(sMembersResult2); Console.WriteLine(string.Join(", ", sMembersResult2)); // >>> Hello, World // STEP_END From c4c4ccc1d56f8bf45baa8db19df41227dc019f6a Mon Sep 17 00:00:00 2001 From: Andy Stark Date: Fri, 27 Jun 2025 13:38:31 +0100 Subject: [PATCH 3/3] DOC-4493 fixed nondeterministic test (again) --- tests/Doc/CmdsSetExample.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Doc/CmdsSetExample.cs b/tests/Doc/CmdsSetExample.cs index f1eb69d4..51c07063 100644 --- a/tests/Doc/CmdsSetExample.cs +++ b/tests/Doc/CmdsSetExample.cs @@ -42,6 +42,7 @@ public void run() Console.WriteLine(sAddResult2); // >>> False RedisValue[] sAddResult4 = db.SetMembers("myset"); + Array.Sort(sAddResult4); Console.WriteLine(string.Join(", ", sAddResult4)); // >>> Hello, World // STEP_END