From 58e65150d334a55ce95a222b2143e223991aebab Mon Sep 17 00:00:00 2001 From: Andy Stark Date: Wed, 10 Apr 2024 09:21:42 +0100 Subject: [PATCH 01/11] DOC-2525 Added tutorial code steps --- tests/Doc/ListTutorial.cs | 319 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 319 insertions(+) create mode 100644 tests/Doc/ListTutorial.cs diff --git a/tests/Doc/ListTutorial.cs b/tests/Doc/ListTutorial.cs new file mode 100644 index 00000000..bb190db6 --- /dev/null +++ b/tests/Doc/ListTutorial.cs @@ -0,0 +1,319 @@ +//EXAMPLE: list_tutorial +//HIDE_START +//REMOVE_START +using NRedisStack.Tests; +//REMOVE_END +using StackExchange.Redis; + +//REMOVE_START +namespace NRedisStack.Doc; +[Collection("DocsTests")] +//REMOVE_END +public class ListExample +{ + //REMOVE_START + [SkipIfRedis(Is.OSSCluster)] + //REMOVE_END + public void run() + { + var muxer = ConnectionMultiplexer.Connect("localhost:6379"); + var db = muxer.GetDatabase(); + //REMOVE_START + db.KeyDelete("bikes:repairs"); + db.KeyDelete("bikes:finished"); + //REMOVE_END + //HIDE_END + + //STEP_START queue + long res1 = db.ListLeftPush("bikes:repairs", "bike:1"); + Console.WriteLine(res1); // >>> 1 + + long res2 = db.ListLeftPush("bikes:repairs", "bike:2"); + Console.WriteLine(res2); // >>> 2 + + RedisValue res3 = db.ListRightPop("bikes:repairs"); + Console.WriteLine(res3); // >>> "bike:1" + + RedisValue res4 = db.ListRightPop("bikes:repairs"); + Console.WriteLine(res4); // >>> "bike:2" + //STEP_END + + //REMOVE_START + Assert.Equal(1, res1); + Assert.Equal(2, res2); + Assert.Equal("bike:1", res3); + Assert.Equal("bike:2", res4); + //REMOVE_END + + //STEP_START stack + long res5 = db.ListLeftPush("bikes:repairs", "bike:1"); + Console.WriteLine(res5); // >>> 1 + + long res6 = db.ListLeftPush("bikes:repairs", "bike:2"); + Console.WriteLine(res6); // >>> 2 + + RedisValue res7 = db.ListLeftPop("bikes:repairs"); + Console.WriteLine(res7); // >>> "bike:2" + + RedisValue res8 = db.ListLeftPop("bikes:repairs"); + Console.WriteLine(res8); // >>> "bike:1" + //STEP_END + + //REMOVE_START + Assert.Equal("bike:2", res7); + Assert.Equal("bike:1", res8); + //REMOVE_END + + + //STEP_START llen + long res9 = db.ListLength("bikes:repairs"); + Console.WriteLine(res9); // >>> 0 + //STEP_END + + //REMOVE_START + Assert.Equal(0, res9); + //REMOVE_END + + + //STEP_START lmove_lrange + long res10 = db.ListLeftPush("bikes:repairs", "bike:1"); + Console.WriteLine(res10); // >>> 1 + + long res11 = db.ListLeftPush("bikes:repairs", "bike:2"); + Console.WriteLine(res11); // >>> 2 + + RedisValue res12 = db.ListMove("bikes:repairs", "bikes:finished", ListSide.Left, ListSide.Left); + Console.Write(res12); // >>> "bike:2" + + RedisValue[] res13 = db.ListRange("bikes:repairs", 0, -1); + Console.WriteLine(string.Join(", ", res13)); // >>> "bike:1" + + RedisValue[] res14 = db.ListRange("bikes:finished", 0, -1); + Console.WriteLine(string.Join(", ", res14)); // >>> "bike:2" + //REMOVE_START + Assert.Equal(1, res10); + Assert.Equal(2, res11); + Assert.Equal("bike:2", res12); + Assert.Equal("bike:1", string.Join(", ", res13)); + Assert.Equal("bike:2", string.Join(", ", res14)); + bool delRes = db.KeyDelete("bikes:repairs"); + //REMOVE_END + //STEP_END + + //STEP_START lpush_rpush + long res15 = db.ListRightPush("bikes:repairs", "bike:1"); + Console.WriteLine(res15); // >>> 1 + + long res16 = db.ListRightPush("bikes:repairs", "bike:2"); + Console.WriteLine(res16); // >>> 2 + + long res17 = db.ListLeftPush("bikes:repairs", "bike:important_bike"); + Console.WriteLine(res17); // >>> 3 + + RedisValue[] res18 = db.ListRange("bikes:repairs", 0, -1); + Console.WriteLine(string.Join(", ", res18)); // >>> "bike:important_bike, bike:1, bike:2" + + //REMOVE_START + Assert.Equal(1, res15); + Assert.Equal(2, res16); + Assert.Equal(3, res17); + Assert.Equal("bike:important_bike, bike:1, bike:2", string.Join(", ", res18)); + delRes = db.KeyDelete("bikes:repairs"); + //REMOVE_END + //STEP_END + + //STEP_START variadic + long res19 = db.ListRightPush("bikes:repairs", ["bike:1", "bike:2", "bike:3"]); + Console.WriteLine(res19); // >>> 3 + + long res20 = db.ListLeftPush("bikes:repairs", ["bike:important_bike", "bike:very_important_bike"]); + Console.WriteLine(res20); // >>> 5 + + RedisValue[] res21 = db.ListRange("bikes:repairs", 0, -1); + Console.WriteLine(string.Join(", ", res21)); // >>> "bike:very_important_bike, bike:important_bike, bike:1, bike:2, bike:3" + + //REMOVE_START + Assert.Equal(3, res19); + Assert.Equal(5, res20); + Assert.Equal("bike:very_important_bike, bike:important_bike, bike:1, bike:2, bike:3", string.Join(", ", res21)); + delRes = db.KeyDelete("bikes:repairs"); + //REMOVE_END + //STEP_END + + //STEP_START lpop_rpop + long res22 = db.ListRightPush("bikes:repairs", ["bike:1", "bike:2", "bike:3"]); + Console.WriteLine(res22); // >>> 3 + + RedisValue res23 = db.ListRightPop("bikes:repairs"); + Console.WriteLine(res23); // >>> "bike:3" + + RedisValue res24 = db.ListLeftPop("bikes:repairs"); + Console.WriteLine(res24); // >>> "bike:1" + + RedisValue res25 = db.ListRightPop("bikes:repairs"); + Console.WriteLine(res25); // >>> "bike:2" + + RedisValue res26 = db.ListRightPop("bikes:repairs"); + Console.WriteLine(res26); // >>> + + //REMOVE_START + Assert.Equal(3, res22); + Assert.Equal("bike:3", res23); + Assert.Equal("bike:1", res24); + Assert.Equal("bike:2", res25); + Assert.Equal("", string.Join(", ", res26)); + //REMOVE_END + //STEP_END + + //STEP_START ltrim + long res27 = db.ListLeftPush("bikes:repairs", ["bike:1", "bike:2", "bike:3", "bike:4", "bike:5"]); + Console.WriteLine(res27); // >>> 5 + + db.ListTrim("bikes:repairs", 0, 2); + RedisValue[] res28 = db.ListRange("bikes:repairs", 0, -1); + Console.WriteLine(string.Join(", ", res28)); // "bike:5, bike:4, bike:3" + + //REMOVE_START + Assert.Equal(5, res27); + Assert.Equal("bike:5, bike:4, bike:3", string.Join(", ", res28)); + delRes = db.KeyDelete("bikes:repairs"); + //REMOVE_END + //STEP_END + + //STEP_START ltrim_end_of_list + long res29 = db.ListRightPush("bikes:repairs", ["bike:1", "bike:2", "bike:3", "bike:4", "bike:5"]); + Console.WriteLine(res29); // >>> 5 + + db.ListTrim("bikes:repairs", -3, -1); + RedisValue[] res30 = db.ListRange("bikes:repairs", 0, -1); + Console.WriteLine(string.Join(", ", res30)); // >>> "bike:3, bike:4, bike:5" + + //REMOVE_START + Assert.Equal(5, res29); + Assert.Equal("bike:3, bike:4, bike:5", string.Join(", ", res30)); + delRes = db.KeyDelete("bikes:repairs"); + //REMOVE_END + //STEP_END + + //STEP_START brpop + long res31 = db.ListRightPush("bikes:repairs", ["bike:1", "bike:2"]); + Console.WriteLine(res31); // >>> 2 + + Tuple? res32 = db.BRPop(["bikes:repairs"], 1); + + if (res32 != null) + Console.WriteLine($"{res32.Item1} -> {res32.Item2}"); // >>> "bikes:repairs -> bike:2" + + Tuple? res33 = db.BRPop(["bikes:repairs"], 1); + + if (res33 != null) + Console.WriteLine($"{res33.Item1} -> {res33.Item2}"); // >>> "bikes:repairs -> bike:1" + + Tuple? res34 = db.BRPop(["bikes:repairs"], 1); + Console.WriteLine(res34); // "Null" + //REMOVE_START + Assert.Equal(2, res31); + + if (res32 != null) + Assert.Equal("bikes:repairs -> bike:2", $"{res32.Item1} -> {res32.Item2}"); + if (res33 != null) + Assert.Equal("bikes:repairs -> bike:1", $"{res33.Item1} -> {res33.Item2}"); + + Assert.Null(res34); + //REMOVE_END + //STEP_END + + //STEP_START rule_1 + bool res35 = db.KeyDelete("new_bikes"); + Console.WriteLine(res35); // >>> False + + long res36 = db.ListRightPush("new_bikes", ["bike:1", "bike:2", "bike:3"]); + Console.WriteLine(res36); // >>> 3 + //REMOVE_START + Assert.False(res35); + Assert.Equal(3, res36); + //REMOVE_END + //STEP_END + + //STEP_START rule_1.1 + bool res37 = db.StringSet("new_bikes", "bike:1"); + Console.WriteLine(res37); // >>> True + + RedisType res38 = db.KeyType("new_bikes"); + Console.WriteLine(res38); // >>> RedisType.String + + try { + long res39 = db.ListRightPush("new_bikes", ["bike:2", "bike:3"]); + } catch(Exception e){ + Console.WriteLine(e); + } + //REMOVE_START + Assert.True(res37); + Assert.Equal(RedisType.String, res38); + delRes = db.KeyDelete("new_bikes"); + //REMOVE_END + //STEP_END + + //STEP_START rule_2 + long res40 = db.ListLeftPush("bikes:repairs", ["bike:1", "bike:2", "bike:3"]); + Console.WriteLine(res40); // >>> 3 + + bool res41 = db.KeyExists("bikes:repairs"); + Console.WriteLine(res41); // >>> True + + RedisValue res42 = db.ListLeftPop("bikes:repairs"); + Console.WriteLine(res42); // >>> "bike:3" + + RedisValue res43 = db.ListLeftPop("bikes:repairs"); + Console.WriteLine(res43); // >>> "bike:2" + + RedisValue res44 = db.ListLeftPop("bikes:repairs"); + Console.WriteLine(res44); // >>> "bike:1" + + bool res45 = db.KeyExists("bikes:repairs"); + Console.WriteLine(res45); // >>> False + + //REMOVE_START + Assert.Equal(3, res40); + Assert.True(res41); + Assert.Equal("bike:3", res42); + Assert.Equal("bike:2", res43); + Assert.Equal("bike:1", res44); + Assert.False(res45); + //REMOVE_END + //STEP_END + + //STEP_START rule_3 + bool res46 = db.KeyDelete("bikes:repairs"); + Console.WriteLine(res46); // >>> False + + long res47 = db.ListLength("bikes:repairs"); + Console.WriteLine(res47); // >>> 0 + + RedisValue res48 = db.ListLeftPop("bikes:repairs"); + Console.WriteLine(res48); // >>> Null + //REMOVE_START + Assert.False(res46); + Assert.Equal(0, res47); + Assert.Equal(RedisValue.Null, res48); + //REMOVE_END + //STEP_END + + //STEP_START ltrim.1 + long res49 = db.ListLeftPush("bikes:repairs", ["bike:1", "bike:2", "bike:3", "bike:4", "bike:5"]); + Console.WriteLine(res49); // >>> 5 + + db.ListTrim("bikes:repairs", 0 , 2); + RedisValue[] res50 = db.ListRange("bikes:repairs", 0, -1); + Console.WriteLine(string.Join(", ", res50)); // >>> "bike:5, bike:4, bike:3" + //STEP_END + + //REMOVE_START + Assert.Equal(5, res49); + Assert.Equal("bike:5, bike:4, bike:3", string.Join(", ", res50)); + //REMOVE_END + + //HIDE_START + } +} +//HIDE_END From 6dae2e258beb4186978d90756e8da982a1e49823 Mon Sep 17 00:00:00 2001 From: Andy Stark Date: Fri, 12 Apr 2024 11:56:27 +0100 Subject: [PATCH 02/11] DOC-2525 added list code samples --- tests/Doc/ListTutorial.cs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/tests/Doc/ListTutorial.cs b/tests/Doc/ListTutorial.cs index bb190db6..f4e096f6 100644 --- a/tests/Doc/ListTutorial.cs +++ b/tests/Doc/ListTutorial.cs @@ -63,7 +63,7 @@ public void run() Assert.Equal("bike:2", res7); Assert.Equal("bike:1", res8); //REMOVE_END - + //STEP_START llen long res9 = db.ListLength("bikes:repairs"); @@ -73,7 +73,7 @@ public void run() //REMOVE_START Assert.Equal(0, res9); //REMOVE_END - + //STEP_START lmove_lrange long res10 = db.ListLeftPush("bikes:repairs", "bike:1"); @@ -131,7 +131,7 @@ public void run() RedisValue[] res21 = db.ListRange("bikes:repairs", 0, -1); Console.WriteLine(string.Join(", ", res21)); // >>> "bike:very_important_bike, bike:important_bike, bike:1, bike:2, bike:3" - + //REMOVE_START Assert.Equal(3, res19); Assert.Equal(5, res20); @@ -198,9 +198,9 @@ public void run() //STEP_START brpop long res31 = db.ListRightPush("bikes:repairs", ["bike:1", "bike:2"]); Console.WriteLine(res31); // >>> 2 - + Tuple? res32 = db.BRPop(["bikes:repairs"], 1); - + if (res32 != null) Console.WriteLine($"{res32.Item1} -> {res32.Item2}"); // >>> "bikes:repairs -> bike:2" @@ -218,7 +218,7 @@ public void run() Assert.Equal("bikes:repairs -> bike:2", $"{res32.Item1} -> {res32.Item2}"); if (res33 != null) Assert.Equal("bikes:repairs -> bike:1", $"{res33.Item1} -> {res33.Item2}"); - + Assert.Null(res34); //REMOVE_END //STEP_END @@ -242,9 +242,12 @@ public void run() RedisType res38 = db.KeyType("new_bikes"); Console.WriteLine(res38); // >>> RedisType.String - try { + try + { long res39 = db.ListRightPush("new_bikes", ["bike:2", "bike:3"]); - } catch(Exception e){ + } + catch (Exception e) + { Console.WriteLine(e); } //REMOVE_START @@ -303,7 +306,7 @@ public void run() long res49 = db.ListLeftPush("bikes:repairs", ["bike:1", "bike:2", "bike:3", "bike:4", "bike:5"]); Console.WriteLine(res49); // >>> 5 - db.ListTrim("bikes:repairs", 0 , 2); + db.ListTrim("bikes:repairs", 0, 2); RedisValue[] res50 = db.ListRange("bikes:repairs", 0, -1); Console.WriteLine(string.Join(", ", res50)); // >>> "bike:5, bike:4, bike:3" //STEP_END From 09f5786a90209f3380fa865c9516ce2cb8787cf7 Mon Sep 17 00:00:00 2001 From: Andy Stark Date: Fri, 12 Apr 2024 12:17:22 +0100 Subject: [PATCH 03/11] DOC-2525 fixed array initialisers --- tests/Doc/ListTutorial.cs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/Doc/ListTutorial.cs b/tests/Doc/ListTutorial.cs index f4e096f6..250ed39b 100644 --- a/tests/Doc/ListTutorial.cs +++ b/tests/Doc/ListTutorial.cs @@ -123,10 +123,10 @@ public void run() //STEP_END //STEP_START variadic - long res19 = db.ListRightPush("bikes:repairs", ["bike:1", "bike:2", "bike:3"]); + long res19 = db.ListRightPush("bikes:repairs", new RedisValue[] { "bike:1", "bike:2", "bike:3" }); Console.WriteLine(res19); // >>> 3 - long res20 = db.ListLeftPush("bikes:repairs", ["bike:important_bike", "bike:very_important_bike"]); + long res20 = db.ListLeftPush("bikes:repairs", new RedisValue[] { "bike:important_bike", "bike:very_important_bike" }); Console.WriteLine(res20); // >>> 5 RedisValue[] res21 = db.ListRange("bikes:repairs", 0, -1); @@ -141,7 +141,7 @@ public void run() //STEP_END //STEP_START lpop_rpop - long res22 = db.ListRightPush("bikes:repairs", ["bike:1", "bike:2", "bike:3"]); + long res22 = db.ListRightPush("bikes:repairs", new RedisValue[] { "bike:1", "bike:2", "bike:3" }); Console.WriteLine(res22); // >>> 3 RedisValue res23 = db.ListRightPop("bikes:repairs"); @@ -166,7 +166,7 @@ public void run() //STEP_END //STEP_START ltrim - long res27 = db.ListLeftPush("bikes:repairs", ["bike:1", "bike:2", "bike:3", "bike:4", "bike:5"]); + long res27 = db.ListLeftPush("bikes:repairs", new RedisValue[] { "bike:1", "bike:2", "bike:3", "bike:4", "bike:5" }); Console.WriteLine(res27); // >>> 5 db.ListTrim("bikes:repairs", 0, 2); @@ -181,7 +181,7 @@ public void run() //STEP_END //STEP_START ltrim_end_of_list - long res29 = db.ListRightPush("bikes:repairs", ["bike:1", "bike:2", "bike:3", "bike:4", "bike:5"]); + long res29 = db.ListRightPush("bikes:repairs", new RedisValue[] { "bike:1", "bike:2", "bike:3", "bike:4", "bike:5" }); Console.WriteLine(res29); // >>> 5 db.ListTrim("bikes:repairs", -3, -1); @@ -196,15 +196,15 @@ public void run() //STEP_END //STEP_START brpop - long res31 = db.ListRightPush("bikes:repairs", ["bike:1", "bike:2"]); + long res31 = db.ListRightPush("bikes:repairs", new RedisValue[] { "bike:1", "bike:2" }); Console.WriteLine(res31); // >>> 2 - Tuple? res32 = db.BRPop(["bikes:repairs"], 1); + Tuple? res32 = db.BRPop(new RedisKey[] { "bikes:repairs" }, 1); if (res32 != null) Console.WriteLine($"{res32.Item1} -> {res32.Item2}"); // >>> "bikes:repairs -> bike:2" - Tuple? res33 = db.BRPop(["bikes:repairs"], 1); + Tuple? res33 = db.BRPop(new RedisKey[] { "bikes:repairs" }, 1); if (res33 != null) Console.WriteLine($"{res33.Item1} -> {res33.Item2}"); // >>> "bikes:repairs -> bike:1" @@ -227,7 +227,7 @@ public void run() bool res35 = db.KeyDelete("new_bikes"); Console.WriteLine(res35); // >>> False - long res36 = db.ListRightPush("new_bikes", ["bike:1", "bike:2", "bike:3"]); + long res36 = db.ListRightPush("new_bikes", new RedisValue[] { "bike:1", "bike:2", "bike:3" }); Console.WriteLine(res36); // >>> 3 //REMOVE_START Assert.False(res35); @@ -244,7 +244,7 @@ public void run() try { - long res39 = db.ListRightPush("new_bikes", ["bike:2", "bike:3"]); + long res39 = db.ListRightPush("new_bikes", new RedisValue[] { "bike:2", "bike:3" }); } catch (Exception e) { @@ -258,7 +258,7 @@ public void run() //STEP_END //STEP_START rule_2 - long res40 = db.ListLeftPush("bikes:repairs", ["bike:1", "bike:2", "bike:3"]); + long res40 = db.ListLeftPush("bikes:repairs", new RedisValue[] { "bike:1", "bike:2", "bike:3" }); Console.WriteLine(res40); // >>> 3 bool res41 = db.KeyExists("bikes:repairs"); @@ -303,7 +303,7 @@ public void run() //STEP_END //STEP_START ltrim.1 - long res49 = db.ListLeftPush("bikes:repairs", ["bike:1", "bike:2", "bike:3", "bike:4", "bike:5"]); + long res49 = db.ListLeftPush("bikes:repairs", new RedisValue[] { "bike:1", "bike:2", "bike:3", "bike:4", "bike:5" }); Console.WriteLine(res49); // >>> 5 db.ListTrim("bikes:repairs", 0, 2); From 4b169bfacf2d47cc5e750dd0dde61e3e46d0e6d7 Mon Sep 17 00:00:00 2001 From: Andy Stark Date: Fri, 12 Apr 2024 12:33:48 +0100 Subject: [PATCH 04/11] DOC-2525 fixed cross slot errors with ListMove --- tests/Doc/ListTutorial.cs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tests/Doc/ListTutorial.cs b/tests/Doc/ListTutorial.cs index 250ed39b..31b4a87c 100644 --- a/tests/Doc/ListTutorial.cs +++ b/tests/Doc/ListTutorial.cs @@ -21,6 +21,8 @@ public void run() //REMOVE_START db.KeyDelete("bikes:repairs"); db.KeyDelete("bikes:finished"); + db.KeyDelete("{bikes}:repairs"); + db.KeyDelete("{bikes}:finished"); //REMOVE_END //HIDE_END @@ -76,19 +78,19 @@ public void run() //STEP_START lmove_lrange - long res10 = db.ListLeftPush("bikes:repairs", "bike:1"); + long res10 = db.ListLeftPush("{bikes}:repairs", "bike:1"); Console.WriteLine(res10); // >>> 1 - long res11 = db.ListLeftPush("bikes:repairs", "bike:2"); + long res11 = db.ListLeftPush("{bikes}:repairs", "bike:2"); Console.WriteLine(res11); // >>> 2 - RedisValue res12 = db.ListMove("bikes:repairs", "bikes:finished", ListSide.Left, ListSide.Left); + RedisValue res12 = db.ListMove("{bikes}:repairs", "{bikes}:finished", ListSide.Left, ListSide.Left); Console.Write(res12); // >>> "bike:2" - RedisValue[] res13 = db.ListRange("bikes:repairs", 0, -1); + RedisValue[] res13 = db.ListRange("{bikes}:repairs", 0, -1); Console.WriteLine(string.Join(", ", res13)); // >>> "bike:1" - RedisValue[] res14 = db.ListRange("bikes:finished", 0, -1); + RedisValue[] res14 = db.ListRange("{bikes}:finished", 0, -1); Console.WriteLine(string.Join(", ", res14)); // >>> "bike:2" //REMOVE_START Assert.Equal(1, res10); @@ -96,7 +98,8 @@ public void run() Assert.Equal("bike:2", res12); Assert.Equal("bike:1", string.Join(", ", res13)); Assert.Equal("bike:2", string.Join(", ", res14)); - bool delRes = db.KeyDelete("bikes:repairs"); + bool delRes = db.KeyDelete("{bikes}:repairs"); + delRes = db.KeyDelete("{bikes}:finished"); //REMOVE_END //STEP_END From 727415ee9e99d231df0ac0fc7c71bea138679ca1 Mon Sep 17 00:00:00 2001 From: Andy Stark Date: Fri, 12 Apr 2024 12:40:20 +0100 Subject: [PATCH 05/11] DOC-2525 fixed outstanding array initialisers --- tests/Doc/ListTutorial.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Doc/ListTutorial.cs b/tests/Doc/ListTutorial.cs index 31b4a87c..0a614357 100644 --- a/tests/Doc/ListTutorial.cs +++ b/tests/Doc/ListTutorial.cs @@ -212,7 +212,7 @@ public void run() if (res33 != null) Console.WriteLine($"{res33.Item1} -> {res33.Item2}"); // >>> "bikes:repairs -> bike:1" - Tuple? res34 = db.BRPop(["bikes:repairs"], 1); + Tuple? res34 = db.BRPop(new RedisKey[] {"bikes:repairs"}, 1); Console.WriteLine(res34); // "Null" //REMOVE_START Assert.Equal(2, res31); From da7bf357927bac861850a02495fcc674d33ee024 Mon Sep 17 00:00:00 2001 From: Andy Stark Date: Mon, 15 Apr 2024 09:24:53 +0100 Subject: [PATCH 06/11] DOC-2525 dotnet format changes --- tests/Doc/ListTutorial.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Doc/ListTutorial.cs b/tests/Doc/ListTutorial.cs index 0a614357..95a45b52 100644 --- a/tests/Doc/ListTutorial.cs +++ b/tests/Doc/ListTutorial.cs @@ -212,7 +212,7 @@ public void run() if (res33 != null) Console.WriteLine($"{res33.Item1} -> {res33.Item2}"); // >>> "bikes:repairs -> bike:1" - Tuple? res34 = db.BRPop(new RedisKey[] {"bikes:repairs"}, 1); + Tuple? res34 = db.BRPop(new RedisKey[] { "bikes:repairs" }, 1); Console.WriteLine(res34); // "Null" //REMOVE_START Assert.Equal(2, res31); From 7c3546e596c16fda07f9604fd5bec6adf575de1e Mon Sep 17 00:00:00 2001 From: Andy Stark Date: Mon, 15 Apr 2024 09:53:05 +0100 Subject: [PATCH 07/11] DOC-2525 moved REMOVE_START/END bits outside steps for consistency --- tests/Doc/ListTutorial.cs | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/tests/Doc/ListTutorial.cs b/tests/Doc/ListTutorial.cs index 95a45b52..9fb0c1c7 100644 --- a/tests/Doc/ListTutorial.cs +++ b/tests/Doc/ListTutorial.cs @@ -92,6 +92,8 @@ public void run() RedisValue[] res14 = db.ListRange("{bikes}:finished", 0, -1); Console.WriteLine(string.Join(", ", res14)); // >>> "bike:2" + //STEP_END + //REMOVE_START Assert.Equal(1, res10); Assert.Equal(2, res11); @@ -101,7 +103,6 @@ public void run() bool delRes = db.KeyDelete("{bikes}:repairs"); delRes = db.KeyDelete("{bikes}:finished"); //REMOVE_END - //STEP_END //STEP_START lpush_rpush long res15 = db.ListRightPush("bikes:repairs", "bike:1"); @@ -115,7 +116,8 @@ public void run() RedisValue[] res18 = db.ListRange("bikes:repairs", 0, -1); Console.WriteLine(string.Join(", ", res18)); // >>> "bike:important_bike, bike:1, bike:2" - + //STEP_END + //REMOVE_START Assert.Equal(1, res15); Assert.Equal(2, res16); @@ -123,7 +125,6 @@ public void run() Assert.Equal("bike:important_bike, bike:1, bike:2", string.Join(", ", res18)); delRes = db.KeyDelete("bikes:repairs"); //REMOVE_END - //STEP_END //STEP_START variadic long res19 = db.ListRightPush("bikes:repairs", new RedisValue[] { "bike:1", "bike:2", "bike:3" }); @@ -134,14 +135,14 @@ public void run() RedisValue[] res21 = db.ListRange("bikes:repairs", 0, -1); Console.WriteLine(string.Join(", ", res21)); // >>> "bike:very_important_bike, bike:important_bike, bike:1, bike:2, bike:3" - + //STEP_END + //REMOVE_START Assert.Equal(3, res19); Assert.Equal(5, res20); Assert.Equal("bike:very_important_bike, bike:important_bike, bike:1, bike:2, bike:3", string.Join(", ", res21)); delRes = db.KeyDelete("bikes:repairs"); //REMOVE_END - //STEP_END //STEP_START lpop_rpop long res22 = db.ListRightPush("bikes:repairs", new RedisValue[] { "bike:1", "bike:2", "bike:3" }); @@ -158,7 +159,8 @@ public void run() RedisValue res26 = db.ListRightPop("bikes:repairs"); Console.WriteLine(res26); // >>> - + //STEP_END + //REMOVE_START Assert.Equal(3, res22); Assert.Equal("bike:3", res23); @@ -166,7 +168,6 @@ public void run() Assert.Equal("bike:2", res25); Assert.Equal("", string.Join(", ", res26)); //REMOVE_END - //STEP_END //STEP_START ltrim long res27 = db.ListLeftPush("bikes:repairs", new RedisValue[] { "bike:1", "bike:2", "bike:3", "bike:4", "bike:5" }); @@ -175,13 +176,13 @@ public void run() db.ListTrim("bikes:repairs", 0, 2); RedisValue[] res28 = db.ListRange("bikes:repairs", 0, -1); Console.WriteLine(string.Join(", ", res28)); // "bike:5, bike:4, bike:3" - + //STEP_END + //REMOVE_START Assert.Equal(5, res27); Assert.Equal("bike:5, bike:4, bike:3", string.Join(", ", res28)); delRes = db.KeyDelete("bikes:repairs"); //REMOVE_END - //STEP_END //STEP_START ltrim_end_of_list long res29 = db.ListRightPush("bikes:repairs", new RedisValue[] { "bike:1", "bike:2", "bike:3", "bike:4", "bike:5" }); @@ -190,13 +191,13 @@ public void run() db.ListTrim("bikes:repairs", -3, -1); RedisValue[] res30 = db.ListRange("bikes:repairs", 0, -1); Console.WriteLine(string.Join(", ", res30)); // >>> "bike:3, bike:4, bike:5" - + //STEP_END + //REMOVE_START Assert.Equal(5, res29); Assert.Equal("bike:3, bike:4, bike:5", string.Join(", ", res30)); delRes = db.KeyDelete("bikes:repairs"); //REMOVE_END - //STEP_END //STEP_START brpop long res31 = db.ListRightPush("bikes:repairs", new RedisValue[] { "bike:1", "bike:2" }); @@ -214,6 +215,8 @@ public void run() Tuple? res34 = db.BRPop(new RedisKey[] { "bikes:repairs" }, 1); Console.WriteLine(res34); // "Null" + //STEP_END + //REMOVE_START Assert.Equal(2, res31); @@ -224,7 +227,6 @@ public void run() Assert.Null(res34); //REMOVE_END - //STEP_END //STEP_START rule_1 bool res35 = db.KeyDelete("new_bikes"); @@ -232,11 +234,12 @@ public void run() long res36 = db.ListRightPush("new_bikes", new RedisValue[] { "bike:1", "bike:2", "bike:3" }); Console.WriteLine(res36); // >>> 3 + //STEP_END + //REMOVE_START Assert.False(res35); Assert.Equal(3, res36); //REMOVE_END - //STEP_END //STEP_START rule_1.1 bool res37 = db.StringSet("new_bikes", "bike:1"); @@ -253,12 +256,13 @@ public void run() { Console.WriteLine(e); } + //STEP_END + //REMOVE_START Assert.True(res37); Assert.Equal(RedisType.String, res38); delRes = db.KeyDelete("new_bikes"); //REMOVE_END - //STEP_END //STEP_START rule_2 long res40 = db.ListLeftPush("bikes:repairs", new RedisValue[] { "bike:1", "bike:2", "bike:3" }); @@ -278,7 +282,8 @@ public void run() bool res45 = db.KeyExists("bikes:repairs"); Console.WriteLine(res45); // >>> False - + //STEP_END + //REMOVE_START Assert.Equal(3, res40); Assert.True(res41); @@ -287,7 +292,6 @@ public void run() Assert.Equal("bike:1", res44); Assert.False(res45); //REMOVE_END - //STEP_END //STEP_START rule_3 bool res46 = db.KeyDelete("bikes:repairs"); @@ -298,12 +302,13 @@ public void run() RedisValue res48 = db.ListLeftPop("bikes:repairs"); Console.WriteLine(res48); // >>> Null + //STEP_END + //REMOVE_START Assert.False(res46); Assert.Equal(0, res47); Assert.Equal(RedisValue.Null, res48); //REMOVE_END - //STEP_END //STEP_START ltrim.1 long res49 = db.ListLeftPush("bikes:repairs", new RedisValue[] { "bike:1", "bike:2", "bike:3", "bike:4", "bike:5" }); From 002f0412a67271001dc43ff0d9d9dcdb310a9ca2 Mon Sep 17 00:00:00 2001 From: Andy Stark Date: Mon, 15 Apr 2024 10:13:23 +0100 Subject: [PATCH 08/11] DOC-2525 dotnet format changes --- tests/Doc/ListTutorial.cs | 42 +++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/tests/Doc/ListTutorial.cs b/tests/Doc/ListTutorial.cs index 9fb0c1c7..4cad5774 100644 --- a/tests/Doc/ListTutorial.cs +++ b/tests/Doc/ListTutorial.cs @@ -92,8 +92,8 @@ public void run() RedisValue[] res14 = db.ListRange("{bikes}:finished", 0, -1); Console.WriteLine(string.Join(", ", res14)); // >>> "bike:2" - //STEP_END - + //STEP_END + //REMOVE_START Assert.Equal(1, res10); Assert.Equal(2, res11); @@ -116,8 +116,8 @@ public void run() RedisValue[] res18 = db.ListRange("bikes:repairs", 0, -1); Console.WriteLine(string.Join(", ", res18)); // >>> "bike:important_bike, bike:1, bike:2" - //STEP_END - + //STEP_END + //REMOVE_START Assert.Equal(1, res15); Assert.Equal(2, res16); @@ -135,8 +135,8 @@ public void run() RedisValue[] res21 = db.ListRange("bikes:repairs", 0, -1); Console.WriteLine(string.Join(", ", res21)); // >>> "bike:very_important_bike, bike:important_bike, bike:1, bike:2, bike:3" - //STEP_END - + //STEP_END + //REMOVE_START Assert.Equal(3, res19); Assert.Equal(5, res20); @@ -159,8 +159,8 @@ public void run() RedisValue res26 = db.ListRightPop("bikes:repairs"); Console.WriteLine(res26); // >>> - //STEP_END - + //STEP_END + //REMOVE_START Assert.Equal(3, res22); Assert.Equal("bike:3", res23); @@ -176,8 +176,8 @@ public void run() db.ListTrim("bikes:repairs", 0, 2); RedisValue[] res28 = db.ListRange("bikes:repairs", 0, -1); Console.WriteLine(string.Join(", ", res28)); // "bike:5, bike:4, bike:3" - //STEP_END - + //STEP_END + //REMOVE_START Assert.Equal(5, res27); Assert.Equal("bike:5, bike:4, bike:3", string.Join(", ", res28)); @@ -191,8 +191,8 @@ public void run() db.ListTrim("bikes:repairs", -3, -1); RedisValue[] res30 = db.ListRange("bikes:repairs", 0, -1); Console.WriteLine(string.Join(", ", res30)); // >>> "bike:3, bike:4, bike:5" - //STEP_END - + //STEP_END + //REMOVE_START Assert.Equal(5, res29); Assert.Equal("bike:3, bike:4, bike:5", string.Join(", ", res30)); @@ -215,8 +215,8 @@ public void run() Tuple? res34 = db.BRPop(new RedisKey[] { "bikes:repairs" }, 1); Console.WriteLine(res34); // "Null" - //STEP_END - + //STEP_END + //REMOVE_START Assert.Equal(2, res31); @@ -234,8 +234,8 @@ public void run() long res36 = db.ListRightPush("new_bikes", new RedisValue[] { "bike:1", "bike:2", "bike:3" }); Console.WriteLine(res36); // >>> 3 - //STEP_END - + //STEP_END + //REMOVE_START Assert.False(res35); Assert.Equal(3, res36); @@ -257,7 +257,7 @@ public void run() Console.WriteLine(e); } //STEP_END - + //REMOVE_START Assert.True(res37); Assert.Equal(RedisType.String, res38); @@ -282,8 +282,8 @@ public void run() bool res45 = db.KeyExists("bikes:repairs"); Console.WriteLine(res45); // >>> False - //STEP_END - + //STEP_END + //REMOVE_START Assert.Equal(3, res40); Assert.True(res41); @@ -302,8 +302,8 @@ public void run() RedisValue res48 = db.ListLeftPop("bikes:repairs"); Console.WriteLine(res48); // >>> Null - //STEP_END - + //STEP_END + //REMOVE_START Assert.False(res46); Assert.Equal(0, res47); From 54cc2a3867a5f5a0f962fb0d03dc6462e06614f6 Mon Sep 17 00:00:00 2001 From: Andy Stark Date: Mon, 15 Apr 2024 11:06:43 +0100 Subject: [PATCH 09/11] DOC-2525 tidied formatting slightly --- tests/Doc/ListTutorial.cs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/Doc/ListTutorial.cs b/tests/Doc/ListTutorial.cs index 4cad5774..7e51d625 100644 --- a/tests/Doc/ListTutorial.cs +++ b/tests/Doc/ListTutorial.cs @@ -92,7 +92,7 @@ public void run() RedisValue[] res14 = db.ListRange("{bikes}:finished", 0, -1); Console.WriteLine(string.Join(", ", res14)); // >>> "bike:2" - //STEP_END + //STEP_END //REMOVE_START Assert.Equal(1, res10); @@ -116,7 +116,7 @@ public void run() RedisValue[] res18 = db.ListRange("bikes:repairs", 0, -1); Console.WriteLine(string.Join(", ", res18)); // >>> "bike:important_bike, bike:1, bike:2" - //STEP_END + //STEP_END //REMOVE_START Assert.Equal(1, res15); @@ -135,7 +135,7 @@ public void run() RedisValue[] res21 = db.ListRange("bikes:repairs", 0, -1); Console.WriteLine(string.Join(", ", res21)); // >>> "bike:very_important_bike, bike:important_bike, bike:1, bike:2, bike:3" - //STEP_END + //STEP_END //REMOVE_START Assert.Equal(3, res19); @@ -159,7 +159,7 @@ public void run() RedisValue res26 = db.ListRightPop("bikes:repairs"); Console.WriteLine(res26); // >>> - //STEP_END + //STEP_END //REMOVE_START Assert.Equal(3, res22); @@ -176,7 +176,7 @@ public void run() db.ListTrim("bikes:repairs", 0, 2); RedisValue[] res28 = db.ListRange("bikes:repairs", 0, -1); Console.WriteLine(string.Join(", ", res28)); // "bike:5, bike:4, bike:3" - //STEP_END + //STEP_END //REMOVE_START Assert.Equal(5, res27); @@ -191,7 +191,7 @@ public void run() db.ListTrim("bikes:repairs", -3, -1); RedisValue[] res30 = db.ListRange("bikes:repairs", 0, -1); Console.WriteLine(string.Join(", ", res30)); // >>> "bike:3, bike:4, bike:5" - //STEP_END + //STEP_END //REMOVE_START Assert.Equal(5, res29); @@ -214,8 +214,8 @@ public void run() Console.WriteLine($"{res33.Item1} -> {res33.Item2}"); // >>> "bikes:repairs -> bike:1" Tuple? res34 = db.BRPop(new RedisKey[] { "bikes:repairs" }, 1); - Console.WriteLine(res34); // "Null" - //STEP_END + Console.WriteLine(res34); // >>> "Null" + //STEP_END //REMOVE_START Assert.Equal(2, res31); @@ -234,7 +234,7 @@ public void run() long res36 = db.ListRightPush("new_bikes", new RedisValue[] { "bike:1", "bike:2", "bike:3" }); Console.WriteLine(res36); // >>> 3 - //STEP_END + //STEP_END //REMOVE_START Assert.False(res35); @@ -282,7 +282,7 @@ public void run() bool res45 = db.KeyExists("bikes:repairs"); Console.WriteLine(res45); // >>> False - //STEP_END + //STEP_END //REMOVE_START Assert.Equal(3, res40); @@ -302,7 +302,7 @@ public void run() RedisValue res48 = db.ListLeftPop("bikes:repairs"); Console.WriteLine(res48); // >>> Null - //STEP_END + //STEP_END //REMOVE_START Assert.False(res46); From c7ff34dc826696b3d018c745ead66fe9c72e6ae8 Mon Sep 17 00:00:00 2001 From: atakavci Date: Mon, 29 Jul 2024 14:27:59 +0300 Subject: [PATCH 10/11] avoid parallel run in xunit --- .github/workflows/reusable.yml | 6 +++++- Test.proj | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 Test.proj diff --git a/.github/workflows/reusable.yml b/.github/workflows/reusable.yml index 48712181..da3eb34b 100644 --- a/.github/workflows/reusable.yml +++ b/.github/workflows/reusable.yml @@ -65,12 +65,16 @@ jobs: run: dotnet restore - name: Build run: dotnet build --no-restore /p:ContinuousIntegrationBuild=true + # Test.proj to avoid assembly parallelization in dotnet test + # Please see the links + # - https://github.com/nunit/nunit3-vs-adapter/issues/657#issuecomment-596943419 + # - https://github.com/dotnet/sdk/issues/10178#issuecomment-564311592 - name: Test run: | echo "${{secrets.REDIS_CA_PEM}}" > tests/NRedisStack.Tests/bin/Debug/${{inputs.clr_version}}/redis_ca.pem echo "${{secrets.REDIS_USER_CRT}}" > tests/NRedisStack.Tests/bin/Debug/${{inputs.clr_version}}/redis_user.crt echo "${{secrets.REDIS_USER_PRIVATE_KEY}}" > tests/NRedisStack.Tests/bin/Debug/${{inputs.clr_version}}/redis_user_private.key - dotnet test -f ${{inputs.clr_version}} --no-build --verbosity normal /p:CollectCoverage=true /p:CoverletOutputFormat=opencover + dotnet test -f ${{inputs.clr_version}} --no-build --verbosity normal /p:CollectCoverage=true /p:CoverletOutputFormat=opencover -p:BuildInParallel=false Test.proj - name: Codecov uses: codecov/codecov-action@v3 with: diff --git a/Test.proj b/Test.proj new file mode 100644 index 00000000..a17dd759 --- /dev/null +++ b/Test.proj @@ -0,0 +1,5 @@ + + + + + From 0c0c3531ead8c1b0417ff19bc710c3440cae7fbf Mon Sep 17 00:00:00 2001 From: atakavci Date: Mon, 29 Jul 2024 14:32:28 +0300 Subject: [PATCH 11/11] fix Test.proj location --- .github/workflows/reusable.yml | 2 +- Test.proj => tests/Test.proj | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename Test.proj => tests/Test.proj (100%) diff --git a/.github/workflows/reusable.yml b/.github/workflows/reusable.yml index da3eb34b..168e399e 100644 --- a/.github/workflows/reusable.yml +++ b/.github/workflows/reusable.yml @@ -74,7 +74,7 @@ jobs: echo "${{secrets.REDIS_CA_PEM}}" > tests/NRedisStack.Tests/bin/Debug/${{inputs.clr_version}}/redis_ca.pem echo "${{secrets.REDIS_USER_CRT}}" > tests/NRedisStack.Tests/bin/Debug/${{inputs.clr_version}}/redis_user.crt echo "${{secrets.REDIS_USER_PRIVATE_KEY}}" > tests/NRedisStack.Tests/bin/Debug/${{inputs.clr_version}}/redis_user_private.key - dotnet test -f ${{inputs.clr_version}} --no-build --verbosity normal /p:CollectCoverage=true /p:CoverletOutputFormat=opencover -p:BuildInParallel=false Test.proj + dotnet test -f ${{inputs.clr_version}} --no-build --verbosity normal /p:CollectCoverage=true /p:CoverletOutputFormat=opencover -p:BuildInParallel=false tests/Test.proj - name: Codecov uses: codecov/codecov-action@v3 with: diff --git a/Test.proj b/tests/Test.proj similarity index 100% rename from Test.proj rename to tests/Test.proj