From f1327757c35502762c2bd70d7a57bc349fb57f2c Mon Sep 17 00:00:00 2001 From: Andy Stark Date: Wed, 10 Apr 2024 16:03:30 +0100 Subject: [PATCH 01/14] DOC_2646 Added stream code samples --- tests/Doc/Stream_tutorial.cs | 712 +++++++++++++++++++++++++++++++++++ 1 file changed, 712 insertions(+) create mode 100644 tests/Doc/Stream_tutorial.cs diff --git a/tests/Doc/Stream_tutorial.cs b/tests/Doc/Stream_tutorial.cs new file mode 100644 index 00000000..d74bd27a --- /dev/null +++ b/tests/Doc/Stream_tutorial.cs @@ -0,0 +1,712 @@ +// EXAMPLE: stream_tutorial +// HIDE_START + +using System.Diagnostics; +using System.Runtime.Serialization; +using NRedisStack.Tests; +using StackExchange.Redis; + +// HIDE_END + +// REMOVE_START +namespace Doc; +[Collection("DocsTests")] +// REMOVE_END + +// HIDE_START +public class Stream_tutorial +{ + + [SkipIfRedis(Is.OSSCluster)] + public void run() + { + var muxer = ConnectionMultiplexer.Connect("localhost:6379"); + var db = muxer.GetDatabase(); + //REMOVE_START + // Clear any keys here before using them in tests. + db.KeyDelete("race:france"); + db.KeyDelete("race:italy"); + db.KeyDelete("race:usa"); + //REMOVE_END +// HIDE_END + + string StreamEntryToString(StreamEntry entry) { + string[] values = new string[entry.Values.Length]; + + for (int i = 0; i < entry.Values.Length; i++) { + values[i] = $"{entry.Values[i].Name}: {entry.Values[i].Value}"; + } + + return $"{entry.Id}: [{string.Join(", ", values)}]"; + } + + // STEP_START xadd + RedisValue res1 = db.StreamAdd( + "race:france", + [ + new NameValueEntry("rider", "Castilla"), + new NameValueEntry("speed", 30.2), + new NameValueEntry("position", 1), + new NameValueEntry("location_id", 1) + ] + ); + Console.WriteLine(res1); // >>> 1692629576966-0 + + RedisValue res2 = db.StreamAdd( + "race:france", + [ + new NameValueEntry("rider", "Norem"), + new NameValueEntry("speed", 28.8), + new NameValueEntry("position", 3), + new NameValueEntry("location_id", 1) + ] + ); + Console.WriteLine(res2); // >>> 1692629594113-0 + + RedisValue res3 = db.StreamAdd( + "race:france", + [ + new NameValueEntry("rider", "Prickett"), + new NameValueEntry("speed", 29.7), + new NameValueEntry("position", 2), + new NameValueEntry("location_id", 1) + ] + ); + Console.WriteLine(res3); // >>> 1692629613374-0 + + // STEP_END + + // Tests for 'xadd' step. + // REMOVE_START + Assert.Equal(3, db.StreamLength("race:france")); + // REMOVE_END + + + // STEP_START xrange + StreamEntry[] res4 = db.StreamRange("race:france", "1691765278160-0", "+", 2); + + foreach(StreamEntry entry in res4) { + Console.WriteLine(StreamEntryToString(entry)); + } + + // >>> 1712668482289-0: [rider: Castilla, speed: 30.199999999999999, position: 1, location_id: 1] + // >>> 1712668766534-1: [rider: Norem, speed: 28.800000000000001, position: 3, location_id: 1] + // STEP_END + + // Tests for 'xrange' step. + // REMOVE_START + + // REMOVE_END + + + // STEP_START xread_block + StreamEntry[] res5 = db.StreamRead("race:france", 0, 100); + + foreach(StreamEntry entry in res4) { + Console.WriteLine(StreamEntryToString(entry)); + } + + // >>> 1712668482289-0: [rider: Castilla, speed: 30.199999999999999, position: 1, location_id: 1] + // >>> 1712668766534-1: [rider: Norem, speed: 28.800000000000001, position: 3, location_id: 1] + // >>> 1712669055705-0: [rider: Prickett, speed: 29.699999999999999, position: 2, location_id: 1] + // STEP_END + + // Tests for 'xread_block' step. + // REMOVE_START + + // REMOVE_END + + + // STEP_START xadd_2 + RedisValue res6 = db.StreamAdd( + "race:france", + [ + new NameValueEntry("rider", "Castilla"), + new NameValueEntry("speed", 29.9), + new NameValueEntry("position", 1), + new NameValueEntry("location_id", 2) + ] + ); + + Console.WriteLine(res6); // >>> 1692629676124-0 + // STEP_END + + // Tests for 'xadd_2' step. + // REMOVE_START + + // REMOVE_END + + + // STEP_START xlen + long res7 = db.StreamLength("race:france"); + Console.WriteLine(res7); // >>> 4 + // STEP_END + + // Tests for 'xlen' step. + // REMOVE_START + Assert.Equal(4, res7); + // REMOVE_END + + + // STEP_START xadd_id + RedisValue res8 = db.StreamAdd( + "race:usa", + [ + new NameValueEntry("racer", "Castilla") + ], + "0-1" + ); + Console.WriteLine(res8); // >>> 0-1 + + RedisValue res9 = db.StreamAdd( + "race:usa", + [ + new NameValueEntry("racer", "Norem") + ], + "0-2" + ); + Console.WriteLine(res9); // >>> 0-2 + // STEP_END + + // Tests for 'xadd_id' step. + // REMOVE_START + Assert.Equal(2, db.StreamLength("race:usa")); + // REMOVE_END + + + // STEP_START xadd_bad_id + try { + RedisValue res10 = db.StreamAdd( + "race:usa", + [ + new NameValueEntry("racer", "Prickett") + ], + "0-1" + ); + } catch(RedisServerException ex) { + Console.WriteLine(ex); // >>> ERR The ID specified in XADD is equal or smaller than the target stream top item + } + // STEP_END + + // Tests for 'xadd_bad_id' step. + // REMOVE_START + + // REMOVE_END + + + // STEP_START xadd_7 + RedisValue res11 = db.StreamAdd( + "race:usa", + [ + new NameValueEntry("rider", "Norem") + ], + "0-*" + ); + + Console.WriteLine(res11); // >>> "0-3" + // STEP_END + + // Tests for 'xadd_7' step. + // REMOVE_START + Assert.Equal("0-3", res11); + // REMOVE_END + + + // STEP_START xrange_all + StreamEntry[] res12 = db.StreamRange("race:france", "-", "+"); + + foreach(StreamEntry entry in res12) { + Console.WriteLine(StreamEntryToString(entry)); + } + // >>> 1712668482289-0: [rider: Castilla, speed: 30.199999999999999, position: 1, location_id: 1] + // >>> 1712668766534-1: [rider: Norem, speed: 28.800000000000001, position: 3, location_id: 1] + // >>> 1712669055705-0: [rider: Prickett, speed: 29.699999999999999, position: 2, location_id: 1] + // >>> 1712675674750-0: [rider: Castilla, speed: 29.899999999999999, position: 1, location_id: 2] + // STEP_END + + // Tests for 'xrange_all' step. + // REMOVE_START + Assert.Equal(4, res12.Length); + // REMOVE_END + + + // STEP_START xrange_time + StreamEntry[] res13 = db.StreamRange("race:france", 1712668482289, 1712668482291); + + foreach(StreamEntry entry in res13) { + Console.WriteLine(StreamEntryToString(entry)); + } + // >>> 1712668482289-0: [rider: Castilla, speed: 30.199999999999999, position: 1, location_id: 1] + // STEP_END + + // Tests for 'xrange_time' step. + // REMOVE_START + + // REMOVE_END + + + // STEP_START xrange_step_1 + StreamEntry[] res14 = db.StreamRange("race:france", "-", "+", 2); + + foreach(StreamEntry entry in res14) { + Console.WriteLine(StreamEntryToString(entry)); + } + // >>> 1712668482289-0: [rider: Castilla, speed: 30.199999999999999, position: 1, location_id: 1] + // >>> 1712668766534-1: [rider: Norem, speed: 28.800000000000001, position: 3, location_id: 1] + // STEP_END + + // Tests for 'xrange_step_1' step. + // REMOVE_START + + // REMOVE_END + + + // STEP_START xrange_step_2 + StreamEntry[] res15 = db.StreamRange("race:france", "(1712668766534-1", "+", 2); + + foreach(StreamEntry entry in res15) { + Console.WriteLine(StreamEntryToString(entry)); + } + // >>> 1712669055705-0: [rider: Prickett, speed: 29.699999999999999, position: 2, location_id: 1] + // >>> 1712675674750-0: [rider: Castilla, speed: 29.899999999999999, position: 1, location_id: 2] + // STEP_END + + // Tests for 'xrange_step_2' step. + // REMOVE_START + + // REMOVE_END + + + // STEP_START xrange_empty + StreamEntry[] res16 = db.StreamRange("race:france", "(1712675674750-0", "+", 2); + + foreach(StreamEntry entry in res16) { + Console.WriteLine(StreamEntryToString(entry)); + } + // >>> + // STEP_END + + // Tests for 'xrange_empty' step. + // REMOVE_START + + // REMOVE_END + + + // STEP_START xrevrange + StreamEntry[] res17 = db.StreamRange("race:france", "+", "-", 1, Order.Descending); + + foreach(StreamEntry entry in res17) { + Console.WriteLine(StreamEntryToString(entry)); + } + // >>> 1712675674750-0: [rider: Castilla, speed: 29.899999999999999, position: 1, location_id: 2] + // STEP_END + + // Tests for 'xrevrange' step. + // REMOVE_START + + // REMOVE_END + + + // STEP_START xread + StreamEntry[] res18 = db.StreamRead("race:france", 0, 2); + + foreach(StreamEntry entry in res18) { + Console.WriteLine(StreamEntryToString(entry)); + } + // >>> 1712668482289-0: [rider: Castilla, speed: 30.199999999999999, position: 1, location_id: 1] + // >>> 1712668766534-1: [rider: Norem, speed: 28.800000000000001, position: 3, location_id: 1] + // STEP_END + + // Tests for 'xread' step. + // REMOVE_START + Assert.Equal(2, res18.Length); + // REMOVE_END + + + // STEP_START xgroup_create + bool res19 = db.StreamCreateConsumerGroup("race:france", "france_riders", "$"); + Console.WriteLine(res19); // >>> true + // STEP_END + + // Tests for 'xgroup_create' step. + // REMOVE_START + Assert.True(res19); + // REMOVE_END + + + // STEP_START xgroup_create_mkstream + bool res20 = db.StreamCreateConsumerGroup("race:italy", "italy_riders", "$", true); + Console.WriteLine(res20); // >>> true + // STEP_END + + // Tests for 'xgroup_create_mkstream' step. + // REMOVE_START + Assert.True(res20); + // REMOVE_END + + + // STEP_START xgroup_read + RedisValue groupRes = db.StreamAdd( + "race:italy", + [new NameValueEntry("rider", "Castilla")] + ); // 1712744323758-0 + + groupRes = db.StreamAdd( + "race:italy", + [new NameValueEntry("rider", "Royce")] + ); // 1712744358384-0 + + groupRes = db.StreamAdd( + "race:italy", + [new NameValueEntry("rider", "Sam-Bodden")] + ); // 1712744379676-0 + + groupRes = db.StreamAdd( + "race:italy", + [new NameValueEntry("rider", "Prickett")] + ); // 1712744399401-0 + + groupRes = db.StreamAdd( + "race:italy", + [new NameValueEntry("rider", "Norem")] + ); // 1712744413117-0 + + StreamEntry[] res21 = db.StreamReadGroup("race:italy", "italy_riders", "Alice", ">", 1); + + foreach(StreamEntry entry in res21) { + Console.WriteLine(StreamEntryToString(entry)); + } + // >>> 1712744323758-0: [rider: Castilla] + // STEP_END + + // Tests for 'xgroup_read' step. + // REMOVE_START + Assert.Single(res21); + // REMOVE_END + + + // STEP_START xgroup_read_id + StreamEntry[] res22 = db.StreamReadGroup("race:italy", "italy_riders", "Alice", "0"); + + foreach(StreamEntry entry in res22) { + Console.WriteLine(StreamEntryToString(entry)); + // >>> 1712744323758-0: [rider: Castilla] + } + // STEP_END + + // Tests for 'xgroup_read_id' step. + // REMOVE_START + Assert.Single(res22); + // REMOVE_END + + + // STEP_START xack + long res23 = db.StreamAcknowledge("race:italy", "italy_riders", "1712744323758-0"); + Console.WriteLine(res23); // >>> 1 + + StreamEntry[] res24 = db.StreamReadGroup("race:italy", "italy_riders", "Alice", "0"); + + foreach(StreamEntry entry in res24) { + Console.WriteLine(StreamEntryToString(entry)); + } + // >>> + // STEP_END + + // Tests for 'xack' step. + // REMOVE_START + + // REMOVE_END + + + // STEP_START xgroup_read_bob + StreamEntry[] res25 = db.StreamReadGroup("race:italy", "italy_riders", "Bob", ">", 2); + + foreach(StreamEntry entry in res25) { + Console.WriteLine(StreamEntryToString(entry)); + } + // >>> 1712744358384-0: [rider: Royce] + // >>> 1712744379676-0: [rider: Sam-Bodden] + // STEP_END + + // Tests for 'xgroup_read_bob' step. + // REMOVE_START + + // REMOVE_END + + + // STEP_START xpending + + string StreamPendingInfoToString(StreamPendingInfo info) { + string[] consumerStrs = new string[info.Consumers.Length]; + + for (int i = 0; i < info.Consumers.Length; i++) { + consumerStrs[i] = $"name: {info.Consumers[i].Name}, pending:{info.Consumers[i].PendingMessageCount}"; + } + + return $"pending: {info.PendingMessageCount}, min: {info.LowestPendingMessageId}, max: {info.HighestPendingMessageId}, consumers:[{string.Join(", " , consumerStrs)}]"; + } + + StreamPendingInfo res26 = db.StreamPending("race:italy", "italy_riders"); + Console.WriteLine(StreamPendingInfoToString(res26)); + // >>> pending: 2, min: 1712747506906-0, max: 1712747506907-0, consumers:[name: Bob, pending:2] + // STEP_END + + // Tests for 'xpending' step. + // REMOVE_START + + // REMOVE_END + + + // STEP_START xpending_plus_minus + string StreamPendingMessageInfoToString(StreamPendingMessageInfo info) { + return $"message_id: {info.MessageId}, consumer: {info.ConsumerName}, time_since_delivered: {info.IdleTimeInMilliseconds}, times_delivered: {info.DeliveryCount}"; + } + + StreamPendingMessageInfo[] res27 = db.StreamPendingMessages( + "race:italy", "italy_riders", 10, "", "-", "+" + ); + + foreach(StreamPendingMessageInfo info in res27) { + Console.WriteLine(StreamPendingMessageInfoToString(info)); + } + // >>> message_id: min: 1712747506906-0, consumer: Bob, time_since_delivered: 31084, times_delivered: 1 + // >>> message_id: min: 1712747506907-0, consumer: Bob, time_since_delivered: 31084, times_delivered: 1 + // STEP_END + + // Tests for 'xpending_plus_minus' step. + // REMOVE_START + + // REMOVE_END + + + // STEP_START xrange_pending + StreamEntry[] res28 = db.StreamRange("race:italy", "1712744358384-0", "1712744358384-0"); + + foreach(StreamEntry entry in res28) { + Console.WriteLine(StreamEntryToString(entry)); + } + // >>> 1712744358384-0: [rider: Royce] + // STEP_END + + // Tests for 'xrange_pending' step. + // REMOVE_START + + // REMOVE_END + + + // STEP_START xclaim + StreamEntry[] res29 = db.StreamClaim( + "race:italy", "italy_riders", "Alice", 60000, [1712744358384-0] + ); + + foreach(StreamEntry entry in res29) { + Console.WriteLine(StreamEntryToString(entry)); + } + // >>> 1712744358384-0: [rider: Royce] + // STEP_END + + // Tests for 'xclaim' step. + // REMOVE_START + + // REMOVE_END + + + // STEP_START xautoclaim + string StreamAutoClaimResultToString(StreamAutoClaimResult result) { + string[] claimedEntryStrings = new string[result.ClaimedEntries.Length]; + + for (int i = 0; i < claimedEntryStrings.Length; i++) { + claimedEntryStrings[i] = StreamEntryToString(result.ClaimedEntries[i]); + } + + return $"{result.NextStartId}, ({string.Join(", ", claimedEntryStrings)})"; + } + + StreamAutoClaimResult res30 = db.StreamAutoClaim( + "race:italy", "italy_riders", "Alice", 1, "0-0", 1 + ); + + Console.WriteLine(StreamAutoClaimResultToString(res30)); + // >>> 1712744379676-0, (1712744358384-0: [rider: Royce]) + // STEP_END + + // Tests for 'xautoclaim' step. + // REMOVE_START + + // REMOVE_END + + + // STEP_START xautoclaim_cursor + StreamAutoClaimResult res31 = db.StreamAutoClaim( + "race:italy", "italy_riders", "Alice", 1, "(1712744358384-0", 1 + ); + + Console.WriteLine(StreamAutoClaimResultToString(res31)); + // >>> 0-0, (1712744379676-0: [rider: Sam-Bodden]) + // STEP_END + + // Tests for 'xautoclaim_cursor' step. + // REMOVE_START + + // REMOVE_END + + + // STEP_START xinfo + string StreamInfoToString(StreamInfo info) { + return $"length: {info.Length}, radix-tree-keys: {info.RadixTreeKeys}, radix-tree-nodes: {info.RadixTreeNodes}, last-generated-id: {info.LastGeneratedId}, first-entry: {StreamEntryToString(info.FirstEntry)}, last-entry: {StreamEntryToString(info.LastEntry)}"; + } + + StreamInfo res32 = db.StreamInfo("race:italy"); + Console.WriteLine(StreamInfoToString(res32)); + // >>> length: 5, radix-tree-keys: 1, radix-tree-nodes: 2, last-generated-id: 1712756762686-1, first-entry: 1712756762685-0: [rider: Castilla], last-entry: 1712756762686-1: [rider: Norem] + // STEP_END + + // Tests for 'xinfo' step. + // REMOVE_START + + // REMOVE_END + + + // STEP_START xinfo_groups + string StreamGroupInfoToString(StreamGroupInfo info) { + return $"name: {info.Name}, consumers: {info.ConsumerCount}, pending: {info.PendingMessageCount}, last-delivered-id: {info.LastDeliveredId}"; + } + + StreamGroupInfo[] res33 = db.StreamGroupInfo("race:italy"); + + foreach (StreamGroupInfo info in res33) { + Console.WriteLine(StreamGroupInfoToString(info)); + } + // >>> name: italy_riders, consumers: 2, pending: 2, last-delivered-id: 1712757192730-2 + // STEP_END + + // Tests for 'xinfo_groups' step. + // REMOVE_START + + // REMOVE_END + + + // STEP_START xinfo_consumers + string StreamConsumerInfoToString(StreamConsumerInfo info) { + return $"name: {info.Name}, pending: {info.PendingMessageCount}, idle: {info.IdleTimeInMilliseconds}"; + } + + StreamConsumerInfo[] res34 = db.StreamConsumerInfo("race:italy", "italy_riders"); + + foreach (StreamConsumerInfo info in res34) { + Console.WriteLine(StreamConsumerInfoToString(info)); + } + // >>> name: Alice, pending: 1, idle: 7717 + // >>> name: Bob, pending: 0, idle: 7722 + // STEP_END + + // Tests for 'xinfo_consumers' step. + // REMOVE_START + + // REMOVE_END + + + // STEP_START maxlen + db.StreamAdd( + "race:italy", [new NameValueEntry("rider", "Jones")], null, 2, true + ); + + db.StreamAdd( + "race:italy", [new NameValueEntry("rider", "Wood")], null, 2, true + ); + + db.StreamAdd( + "race:italy", [new NameValueEntry("rider", "Henshaw")], null, 2, true + ); + + long res35 = db.StreamLength("race:italy"); + Console.WriteLine(res35); // >>> 8 + + StreamEntry[] res36 = db.StreamRange("race:italy", "-", "+"); + + foreach (StreamEntry entry in res36) { + Console.WriteLine(StreamEntryToString(entry)); + } + // >>> 1712758336128-0: [rider: Castilla] + // >>> 1712758336128-1: [rider: Royce] + // >>> 1712758336128-2: [rider: Sam-Bodden] + // >>> 1712758336129-0: [rider: Prickett] + // >>> 1712758336139-0: [rider: Norem] + // >>> 1712758340854-0: [rider: Jones] + // >>> 1712758341645-0: [rider: Wood] + // >>> 1712758342134-0: [rider: Henshaw] + + db.StreamAdd( + "race:italy", [new NameValueEntry("rider", "Smith")], null, 2, false + ); + + StreamEntry[] res37 = db.StreamRange("race:italy", "-", "+"); + + foreach (StreamEntry entry in res37) { + Console.WriteLine(StreamEntryToString(entry)); + } + // 1712758746476-1: [rider: Henshaw] + // 1712758746477-0: [rider: Smith] + // STEP_END + + // Tests for 'maxlen' step. + // REMOVE_START + + // REMOVE_END + + + // STEP_START xtrim + long res38 = db.StreamTrim("race:italy", 10, false); + Console.WriteLine(res38); // >>> 0 + // STEP_END + + // Tests for 'xtrim' step. + // REMOVE_START + + // REMOVE_END + + + // STEP_START xtrim2 + long res39 = db.StreamTrim("race:italy", 10, false); + Console.WriteLine(res39); // >>> 0 + // STEP_END + + // Tests for 'xtrim2' step. + // REMOVE_START + + // REMOVE_END + + + // STEP_START xdel + StreamEntry[] res40 = db.StreamRange("race:italy", "-", "+"); + + foreach (StreamEntry entry in res40) { + string tmp = StreamEntryToString(entry); + Console.WriteLine(StreamEntryToString(entry)); + } + // >>> 1712759694003-0: [rider: Henshaw] + // >>> 1712759694003-1: [rider: Smith] + + long res41 = db.StreamDelete("race:italy", ["1712759694003-1"]); + Console.WriteLine(res41); // >>> 1 + + StreamEntry[] res42 = db.StreamRange("race:italy", "-", "+"); + + foreach (StreamEntry entry in res42) { + string tmp = StreamEntryToString(entry); + Console.WriteLine(StreamEntryToString(entry)); + } + // >>> 1712759694003-0: [rider: Henshaw] + // STEP_END + + // Tests for 'xdel' step. + // REMOVE_START + + // REMOVE_END + + +// HIDE_START + } +} +// HIDE_END + From ee59ab197e447cd48303157ce934f468e1e6c437 Mon Sep 17 00:00:00 2001 From: Andy Stark Date: Thu, 11 Apr 2024 15:53:17 +0100 Subject: [PATCH 02/14] DOC-2646 Fixed minor issues --- tests/Doc/Stream_tutorial.cs | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/tests/Doc/Stream_tutorial.cs b/tests/Doc/Stream_tutorial.cs index d74bd27a..372bf139 100644 --- a/tests/Doc/Stream_tutorial.cs +++ b/tests/Doc/Stream_tutorial.cs @@ -29,17 +29,7 @@ public void run() db.KeyDelete("race:usa"); //REMOVE_END // HIDE_END - - string StreamEntryToString(StreamEntry entry) { - string[] values = new string[entry.Values.Length]; - - for (int i = 0; i < entry.Values.Length; i++) { - values[i] = $"{entry.Values[i].Name}: {entry.Values[i].Value}"; - } - - return $"{entry.Id}: [{string.Join(", ", values)}]"; - } - + // STEP_START xadd RedisValue res1 = db.StreamAdd( "race:france", @@ -50,7 +40,7 @@ string StreamEntryToString(StreamEntry entry) { new NameValueEntry("location_id", 1) ] ); - Console.WriteLine(res1); // >>> 1692629576966-0 + Console.WriteLine(res1); // >>> 1712668482289-0 RedisValue res2 = db.StreamAdd( "race:france", @@ -61,7 +51,7 @@ string StreamEntryToString(StreamEntry entry) { new NameValueEntry("location_id", 1) ] ); - Console.WriteLine(res2); // >>> 1692629594113-0 + Console.WriteLine(res2); // >>> 1712668766534-1 RedisValue res3 = db.StreamAdd( "race:france", @@ -72,7 +62,7 @@ string StreamEntryToString(StreamEntry entry) { new NameValueEntry("location_id", 1) ] ); - Console.WriteLine(res3); // >>> 1692629613374-0 + Console.WriteLine(res3); // >>> 1712669055705-0 // STEP_END @@ -83,7 +73,17 @@ string StreamEntryToString(StreamEntry entry) { // STEP_START xrange - StreamEntry[] res4 = db.StreamRange("race:france", "1691765278160-0", "+", 2); + string StreamEntryToString(StreamEntry entry) { + string[] values = new string[entry.Values.Length]; + + for (int i = 0; i < entry.Values.Length; i++) { + values[i] = $"{entry.Values[i].Name}: {entry.Values[i].Value}"; + } + + return $"{entry.Id}: [{string.Join(", ", values)}]"; + } + + StreamEntry[] res4 = db.StreamRange("race:france", "1712668482289-0", "+", 2); foreach(StreamEntry entry in res4) { Console.WriteLine(StreamEntryToString(entry)); @@ -128,7 +128,7 @@ string StreamEntryToString(StreamEntry entry) { ] ); - Console.WriteLine(res6); // >>> 1692629676124-0 + Console.WriteLine(res6); // >>> 1712675674750-0 // STEP_END // Tests for 'xadd_2' step. @@ -667,7 +667,7 @@ string StreamConsumerInfoToString(StreamConsumerInfo info) { // STEP_START xtrim2 - long res39 = db.StreamTrim("race:italy", 10, false); + long res39 = db.StreamTrim("race:italy", 10, true); Console.WriteLine(res39); // >>> 0 // STEP_END @@ -681,7 +681,6 @@ string StreamConsumerInfoToString(StreamConsumerInfo info) { StreamEntry[] res40 = db.StreamRange("race:italy", "-", "+"); foreach (StreamEntry entry in res40) { - string tmp = StreamEntryToString(entry); Console.WriteLine(StreamEntryToString(entry)); } // >>> 1712759694003-0: [rider: Henshaw] @@ -693,7 +692,6 @@ string StreamConsumerInfoToString(StreamConsumerInfo info) { StreamEntry[] res42 = db.StreamRange("race:italy", "-", "+"); foreach (StreamEntry entry in res42) { - string tmp = StreamEntryToString(entry); Console.WriteLine(StreamEntryToString(entry)); } // >>> 1712759694003-0: [rider: Henshaw] From 520ba0b85679d52a6f3e45a3ed42d9dea71d5292 Mon Sep 17 00:00:00 2001 From: Andy Stark Date: Thu, 11 Apr 2024 16:33:00 +0100 Subject: [PATCH 03/14] DOC-2646 Fixed array initialisers --- tests/Doc/Stream_tutorial.cs | 56 ++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/tests/Doc/Stream_tutorial.cs b/tests/Doc/Stream_tutorial.cs index 372bf139..e052229a 100644 --- a/tests/Doc/Stream_tutorial.cs +++ b/tests/Doc/Stream_tutorial.cs @@ -33,34 +33,34 @@ public void run() // STEP_START xadd RedisValue res1 = db.StreamAdd( "race:france", - [ + new NameValueEntry[] { new NameValueEntry("rider", "Castilla"), new NameValueEntry("speed", 30.2), new NameValueEntry("position", 1), new NameValueEntry("location_id", 1) - ] + } ); Console.WriteLine(res1); // >>> 1712668482289-0 RedisValue res2 = db.StreamAdd( "race:france", - [ + new NameValueEntry[] { new NameValueEntry("rider", "Norem"), new NameValueEntry("speed", 28.8), new NameValueEntry("position", 3), new NameValueEntry("location_id", 1) - ] + } ); Console.WriteLine(res2); // >>> 1712668766534-1 RedisValue res3 = db.StreamAdd( "race:france", - [ + new NameValueEntry[]{ new NameValueEntry("rider", "Prickett"), new NameValueEntry("speed", 29.7), new NameValueEntry("position", 2), new NameValueEntry("location_id", 1) - ] + } ); Console.WriteLine(res3); // >>> 1712669055705-0 @@ -120,12 +120,12 @@ string StreamEntryToString(StreamEntry entry) { // STEP_START xadd_2 RedisValue res6 = db.StreamAdd( "race:france", - [ + new NameValueEntry[]{ new NameValueEntry("rider", "Castilla"), new NameValueEntry("speed", 29.9), new NameValueEntry("position", 1), new NameValueEntry("location_id", 2) - ] + } ); Console.WriteLine(res6); // >>> 1712675674750-0 @@ -151,18 +151,18 @@ string StreamEntryToString(StreamEntry entry) { // STEP_START xadd_id RedisValue res8 = db.StreamAdd( "race:usa", - [ + new NameValueEntry[] { new NameValueEntry("racer", "Castilla") - ], + }, "0-1" ); Console.WriteLine(res8); // >>> 0-1 RedisValue res9 = db.StreamAdd( "race:usa", - [ + new NameValueEntry[]{ new NameValueEntry("racer", "Norem") - ], + }, "0-2" ); Console.WriteLine(res9); // >>> 0-2 @@ -178,9 +178,9 @@ string StreamEntryToString(StreamEntry entry) { try { RedisValue res10 = db.StreamAdd( "race:usa", - [ + new NameValueEntry[]{ new NameValueEntry("racer", "Prickett") - ], + }, "0-1" ); } catch(RedisServerException ex) { @@ -197,9 +197,9 @@ string StreamEntryToString(StreamEntry entry) { // STEP_START xadd_7 RedisValue res11 = db.StreamAdd( "race:usa", - [ + new NameValueEntry[]{ new NameValueEntry("rider", "Norem") - ], + }, "0-*" ); @@ -348,27 +348,27 @@ string StreamEntryToString(StreamEntry entry) { // STEP_START xgroup_read RedisValue groupRes = db.StreamAdd( "race:italy", - [new NameValueEntry("rider", "Castilla")] + new NameValueEntry[]{new NameValueEntry("rider", "Castilla")} ); // 1712744323758-0 groupRes = db.StreamAdd( "race:italy", - [new NameValueEntry("rider", "Royce")] + new NameValueEntry[]{new NameValueEntry("rider", "Royce")} ); // 1712744358384-0 groupRes = db.StreamAdd( "race:italy", - [new NameValueEntry("rider", "Sam-Bodden")] + new NameValueEntry[]{new NameValueEntry("rider", "Sam-Bodden")} ); // 1712744379676-0 groupRes = db.StreamAdd( "race:italy", - [new NameValueEntry("rider", "Prickett")] + new NameValueEntry[]{new NameValueEntry("rider", "Prickett")} ); // 1712744399401-0 groupRes = db.StreamAdd( "race:italy", - [new NameValueEntry("rider", "Norem")] + new NameValueEntry[]{new NameValueEntry("rider", "Norem")} ); // 1712744413117-0 StreamEntry[] res21 = db.StreamReadGroup("race:italy", "italy_riders", "Alice", ">", 1); @@ -496,7 +496,7 @@ string StreamPendingMessageInfoToString(StreamPendingMessageInfo info) { // STEP_START xclaim StreamEntry[] res29 = db.StreamClaim( - "race:italy", "italy_riders", "Alice", 60000, [1712744358384-0] + "race:italy", "italy_riders", "Alice", 60000, new RedisValue[]{1712744358384-0} ); foreach(StreamEntry entry in res29) { @@ -608,15 +608,15 @@ string StreamConsumerInfoToString(StreamConsumerInfo info) { // STEP_START maxlen db.StreamAdd( - "race:italy", [new NameValueEntry("rider", "Jones")], null, 2, true + "race:italy", new NameValueEntry[]{new NameValueEntry("rider", "Jones")}, null, 2, true ); db.StreamAdd( - "race:italy", [new NameValueEntry("rider", "Wood")], null, 2, true + "race:italy", new NameValueEntry[]{new NameValueEntry("rider", "Wood")}, null, 2, true ); db.StreamAdd( - "race:italy", [new NameValueEntry("rider", "Henshaw")], null, 2, true + "race:italy", new NameValueEntry[]{new NameValueEntry("rider", "Henshaw")}, null, 2, true ); long res35 = db.StreamLength("race:italy"); @@ -637,7 +637,7 @@ string StreamConsumerInfoToString(StreamConsumerInfo info) { // >>> 1712758342134-0: [rider: Henshaw] db.StreamAdd( - "race:italy", [new NameValueEntry("rider", "Smith")], null, 2, false + "race:italy", new NameValueEntry[]{new NameValueEntry("rider", "Smith")}, null, 2, false ); StreamEntry[] res37 = db.StreamRange("race:italy", "-", "+"); @@ -666,7 +666,7 @@ string StreamConsumerInfoToString(StreamConsumerInfo info) { // REMOVE_END - // STEP_START xtrim2 + // STEP_START xtrim2 long res39 = db.StreamTrim("race:italy", 10, true); Console.WriteLine(res39); // >>> 0 // STEP_END @@ -686,7 +686,7 @@ string StreamConsumerInfoToString(StreamConsumerInfo info) { // >>> 1712759694003-0: [rider: Henshaw] // >>> 1712759694003-1: [rider: Smith] - long res41 = db.StreamDelete("race:italy", ["1712759694003-1"]); + long res41 = db.StreamDelete("race:italy", new RedisValue[]{"1712759694003-1"}); Console.WriteLine(res41); // >>> 1 StreamEntry[] res42 = db.StreamRange("race:italy", "-", "+"); From 8ee70a05a0881b96ee19c843283d29359824b114 Mon Sep 17 00:00:00 2001 From: Andy Stark Date: Thu, 11 Apr 2024 16:39:02 +0100 Subject: [PATCH 04/14] DOC-2646 dotnet format changes --- tests/Doc/Stream_tutorial.cs | 143 ++++++++++++++++++++++------------- 1 file changed, 89 insertions(+), 54 deletions(-) diff --git a/tests/Doc/Stream_tutorial.cs b/tests/Doc/Stream_tutorial.cs index e052229a..22e0e362 100644 --- a/tests/Doc/Stream_tutorial.cs +++ b/tests/Doc/Stream_tutorial.cs @@ -16,7 +16,7 @@ namespace Doc; // HIDE_START public class Stream_tutorial { - + [SkipIfRedis(Is.OSSCluster)] public void run() { @@ -28,8 +28,8 @@ public void run() db.KeyDelete("race:italy"); db.KeyDelete("race:usa"); //REMOVE_END -// HIDE_END - + // HIDE_END + // STEP_START xadd RedisValue res1 = db.StreamAdd( "race:france", @@ -73,10 +73,12 @@ public void run() // STEP_START xrange - string StreamEntryToString(StreamEntry entry) { + string StreamEntryToString(StreamEntry entry) + { string[] values = new string[entry.Values.Length]; - for (int i = 0; i < entry.Values.Length; i++) { + for (int i = 0; i < entry.Values.Length; i++) + { values[i] = $"{entry.Values[i].Name}: {entry.Values[i].Value}"; } @@ -85,7 +87,8 @@ string StreamEntryToString(StreamEntry entry) { StreamEntry[] res4 = db.StreamRange("race:france", "1712668482289-0", "+", 2); - foreach(StreamEntry entry in res4) { + foreach (StreamEntry entry in res4) + { Console.WriteLine(StreamEntryToString(entry)); } @@ -102,7 +105,8 @@ string StreamEntryToString(StreamEntry entry) { // STEP_START xread_block StreamEntry[] res5 = db.StreamRead("race:france", 0, 100); - foreach(StreamEntry entry in res4) { + foreach (StreamEntry entry in res4) + { Console.WriteLine(StreamEntryToString(entry)); } @@ -175,7 +179,8 @@ string StreamEntryToString(StreamEntry entry) { // STEP_START xadd_bad_id - try { + try + { RedisValue res10 = db.StreamAdd( "race:usa", new NameValueEntry[]{ @@ -183,7 +188,9 @@ string StreamEntryToString(StreamEntry entry) { }, "0-1" ); - } catch(RedisServerException ex) { + } + catch (RedisServerException ex) + { Console.WriteLine(ex); // >>> ERR The ID specified in XADD is equal or smaller than the target stream top item } // STEP_END @@ -215,7 +222,8 @@ string StreamEntryToString(StreamEntry entry) { // STEP_START xrange_all StreamEntry[] res12 = db.StreamRange("race:france", "-", "+"); - foreach(StreamEntry entry in res12) { + foreach (StreamEntry entry in res12) + { Console.WriteLine(StreamEntryToString(entry)); } // >>> 1712668482289-0: [rider: Castilla, speed: 30.199999999999999, position: 1, location_id: 1] @@ -233,7 +241,8 @@ string StreamEntryToString(StreamEntry entry) { // STEP_START xrange_time StreamEntry[] res13 = db.StreamRange("race:france", 1712668482289, 1712668482291); - foreach(StreamEntry entry in res13) { + foreach (StreamEntry entry in res13) + { Console.WriteLine(StreamEntryToString(entry)); } // >>> 1712668482289-0: [rider: Castilla, speed: 30.199999999999999, position: 1, location_id: 1] @@ -248,7 +257,8 @@ string StreamEntryToString(StreamEntry entry) { // STEP_START xrange_step_1 StreamEntry[] res14 = db.StreamRange("race:france", "-", "+", 2); - foreach(StreamEntry entry in res14) { + foreach (StreamEntry entry in res14) + { Console.WriteLine(StreamEntryToString(entry)); } // >>> 1712668482289-0: [rider: Castilla, speed: 30.199999999999999, position: 1, location_id: 1] @@ -264,7 +274,8 @@ string StreamEntryToString(StreamEntry entry) { // STEP_START xrange_step_2 StreamEntry[] res15 = db.StreamRange("race:france", "(1712668766534-1", "+", 2); - foreach(StreamEntry entry in res15) { + foreach (StreamEntry entry in res15) + { Console.WriteLine(StreamEntryToString(entry)); } // >>> 1712669055705-0: [rider: Prickett, speed: 29.699999999999999, position: 2, location_id: 1] @@ -280,12 +291,13 @@ string StreamEntryToString(StreamEntry entry) { // STEP_START xrange_empty StreamEntry[] res16 = db.StreamRange("race:france", "(1712675674750-0", "+", 2); - foreach(StreamEntry entry in res16) { + foreach (StreamEntry entry in res16) + { Console.WriteLine(StreamEntryToString(entry)); } // >>> // STEP_END - + // Tests for 'xrange_empty' step. // REMOVE_START @@ -295,7 +307,8 @@ string StreamEntryToString(StreamEntry entry) { // STEP_START xrevrange StreamEntry[] res17 = db.StreamRange("race:france", "+", "-", 1, Order.Descending); - foreach(StreamEntry entry in res17) { + foreach (StreamEntry entry in res17) + { Console.WriteLine(StreamEntryToString(entry)); } // >>> 1712675674750-0: [rider: Castilla, speed: 29.899999999999999, position: 1, location_id: 2] @@ -310,7 +323,8 @@ string StreamEntryToString(StreamEntry entry) { // STEP_START xread StreamEntry[] res18 = db.StreamRead("race:france", 0, 2); - foreach(StreamEntry entry in res18) { + foreach (StreamEntry entry in res18) + { Console.WriteLine(StreamEntryToString(entry)); } // >>> 1712668482289-0: [rider: Castilla, speed: 30.199999999999999, position: 1, location_id: 1] @@ -348,32 +362,33 @@ string StreamEntryToString(StreamEntry entry) { // STEP_START xgroup_read RedisValue groupRes = db.StreamAdd( "race:italy", - new NameValueEntry[]{new NameValueEntry("rider", "Castilla")} + new NameValueEntry[] { new NameValueEntry("rider", "Castilla") } ); // 1712744323758-0 groupRes = db.StreamAdd( "race:italy", - new NameValueEntry[]{new NameValueEntry("rider", "Royce")} + new NameValueEntry[] { new NameValueEntry("rider", "Royce") } ); // 1712744358384-0 groupRes = db.StreamAdd( "race:italy", - new NameValueEntry[]{new NameValueEntry("rider", "Sam-Bodden")} + new NameValueEntry[] { new NameValueEntry("rider", "Sam-Bodden") } ); // 1712744379676-0 groupRes = db.StreamAdd( "race:italy", - new NameValueEntry[]{new NameValueEntry("rider", "Prickett")} + new NameValueEntry[] { new NameValueEntry("rider", "Prickett") } ); // 1712744399401-0 groupRes = db.StreamAdd( "race:italy", - new NameValueEntry[]{new NameValueEntry("rider", "Norem")} + new NameValueEntry[] { new NameValueEntry("rider", "Norem") } ); // 1712744413117-0 StreamEntry[] res21 = db.StreamReadGroup("race:italy", "italy_riders", "Alice", ">", 1); - foreach(StreamEntry entry in res21) { + foreach (StreamEntry entry in res21) + { Console.WriteLine(StreamEntryToString(entry)); } // >>> 1712744323758-0: [rider: Castilla] @@ -388,7 +403,8 @@ string StreamEntryToString(StreamEntry entry) { // STEP_START xgroup_read_id StreamEntry[] res22 = db.StreamReadGroup("race:italy", "italy_riders", "Alice", "0"); - foreach(StreamEntry entry in res22) { + foreach (StreamEntry entry in res22) + { Console.WriteLine(StreamEntryToString(entry)); // >>> 1712744323758-0: [rider: Castilla] } @@ -406,7 +422,8 @@ string StreamEntryToString(StreamEntry entry) { StreamEntry[] res24 = db.StreamReadGroup("race:italy", "italy_riders", "Alice", "0"); - foreach(StreamEntry entry in res24) { + foreach (StreamEntry entry in res24) + { Console.WriteLine(StreamEntryToString(entry)); } // >>> @@ -421,7 +438,8 @@ string StreamEntryToString(StreamEntry entry) { // STEP_START xgroup_read_bob StreamEntry[] res25 = db.StreamReadGroup("race:italy", "italy_riders", "Bob", ">", 2); - foreach(StreamEntry entry in res25) { + foreach (StreamEntry entry in res25) + { Console.WriteLine(StreamEntryToString(entry)); } // >>> 1712744358384-0: [rider: Royce] @@ -436,14 +454,16 @@ string StreamEntryToString(StreamEntry entry) { // STEP_START xpending - string StreamPendingInfoToString(StreamPendingInfo info) { + string StreamPendingInfoToString(StreamPendingInfo info) + { string[] consumerStrs = new string[info.Consumers.Length]; - for (int i = 0; i < info.Consumers.Length; i++) { + for (int i = 0; i < info.Consumers.Length; i++) + { consumerStrs[i] = $"name: {info.Consumers[i].Name}, pending:{info.Consumers[i].PendingMessageCount}"; } - - return $"pending: {info.PendingMessageCount}, min: {info.LowestPendingMessageId}, max: {info.HighestPendingMessageId}, consumers:[{string.Join(", " , consumerStrs)}]"; + + return $"pending: {info.PendingMessageCount}, min: {info.LowestPendingMessageId}, max: {info.HighestPendingMessageId}, consumers:[{string.Join(", ", consumerStrs)}]"; } StreamPendingInfo res26 = db.StreamPending("race:italy", "italy_riders"); @@ -458,7 +478,8 @@ string StreamPendingInfoToString(StreamPendingInfo info) { // STEP_START xpending_plus_minus - string StreamPendingMessageInfoToString(StreamPendingMessageInfo info) { + string StreamPendingMessageInfoToString(StreamPendingMessageInfo info) + { return $"message_id: {info.MessageId}, consumer: {info.ConsumerName}, time_since_delivered: {info.IdleTimeInMilliseconds}, times_delivered: {info.DeliveryCount}"; } @@ -466,7 +487,8 @@ string StreamPendingMessageInfoToString(StreamPendingMessageInfo info) { "race:italy", "italy_riders", 10, "", "-", "+" ); - foreach(StreamPendingMessageInfo info in res27) { + foreach (StreamPendingMessageInfo info in res27) + { Console.WriteLine(StreamPendingMessageInfoToString(info)); } // >>> message_id: min: 1712747506906-0, consumer: Bob, time_since_delivered: 31084, times_delivered: 1 @@ -482,7 +504,8 @@ string StreamPendingMessageInfoToString(StreamPendingMessageInfo info) { // STEP_START xrange_pending StreamEntry[] res28 = db.StreamRange("race:italy", "1712744358384-0", "1712744358384-0"); - foreach(StreamEntry entry in res28) { + foreach (StreamEntry entry in res28) + { Console.WriteLine(StreamEntryToString(entry)); } // >>> 1712744358384-0: [rider: Royce] @@ -496,10 +519,11 @@ string StreamPendingMessageInfoToString(StreamPendingMessageInfo info) { // STEP_START xclaim StreamEntry[] res29 = db.StreamClaim( - "race:italy", "italy_riders", "Alice", 60000, new RedisValue[]{1712744358384-0} + "race:italy", "italy_riders", "Alice", 60000, new RedisValue[] { 1712744358384 - 0 } ); - foreach(StreamEntry entry in res29) { + foreach (StreamEntry entry in res29) + { Console.WriteLine(StreamEntryToString(entry)); } // >>> 1712744358384-0: [rider: Royce] @@ -512,10 +536,12 @@ string StreamPendingMessageInfoToString(StreamPendingMessageInfo info) { // STEP_START xautoclaim - string StreamAutoClaimResultToString(StreamAutoClaimResult result) { + string StreamAutoClaimResultToString(StreamAutoClaimResult result) + { string[] claimedEntryStrings = new string[result.ClaimedEntries.Length]; - for (int i = 0; i < claimedEntryStrings.Length; i++) { + for (int i = 0; i < claimedEntryStrings.Length; i++) + { claimedEntryStrings[i] = StreamEntryToString(result.ClaimedEntries[i]); } @@ -525,14 +551,14 @@ string StreamAutoClaimResultToString(StreamAutoClaimResult result) { StreamAutoClaimResult res30 = db.StreamAutoClaim( "race:italy", "italy_riders", "Alice", 1, "0-0", 1 ); - + Console.WriteLine(StreamAutoClaimResultToString(res30)); // >>> 1712744379676-0, (1712744358384-0: [rider: Royce]) // STEP_END // Tests for 'xautoclaim' step. // REMOVE_START - + // REMOVE_END @@ -552,7 +578,8 @@ string StreamAutoClaimResultToString(StreamAutoClaimResult result) { // STEP_START xinfo - string StreamInfoToString(StreamInfo info) { + string StreamInfoToString(StreamInfo info) + { return $"length: {info.Length}, radix-tree-keys: {info.RadixTreeKeys}, radix-tree-nodes: {info.RadixTreeNodes}, last-generated-id: {info.LastGeneratedId}, first-entry: {StreamEntryToString(info.FirstEntry)}, last-entry: {StreamEntryToString(info.LastEntry)}"; } @@ -568,13 +595,15 @@ string StreamInfoToString(StreamInfo info) { // STEP_START xinfo_groups - string StreamGroupInfoToString(StreamGroupInfo info) { + string StreamGroupInfoToString(StreamGroupInfo info) + { return $"name: {info.Name}, consumers: {info.ConsumerCount}, pending: {info.PendingMessageCount}, last-delivered-id: {info.LastDeliveredId}"; } StreamGroupInfo[] res33 = db.StreamGroupInfo("race:italy"); - foreach (StreamGroupInfo info in res33) { + foreach (StreamGroupInfo info in res33) + { Console.WriteLine(StreamGroupInfoToString(info)); } // >>> name: italy_riders, consumers: 2, pending: 2, last-delivered-id: 1712757192730-2 @@ -587,13 +616,15 @@ string StreamGroupInfoToString(StreamGroupInfo info) { // STEP_START xinfo_consumers - string StreamConsumerInfoToString(StreamConsumerInfo info) { + string StreamConsumerInfoToString(StreamConsumerInfo info) + { return $"name: {info.Name}, pending: {info.PendingMessageCount}, idle: {info.IdleTimeInMilliseconds}"; } StreamConsumerInfo[] res34 = db.StreamConsumerInfo("race:italy", "italy_riders"); - foreach (StreamConsumerInfo info in res34) { + foreach (StreamConsumerInfo info in res34) + { Console.WriteLine(StreamConsumerInfoToString(info)); } // >>> name: Alice, pending: 1, idle: 7717 @@ -608,15 +639,15 @@ string StreamConsumerInfoToString(StreamConsumerInfo info) { // STEP_START maxlen db.StreamAdd( - "race:italy", new NameValueEntry[]{new NameValueEntry("rider", "Jones")}, null, 2, true + "race:italy", new NameValueEntry[] { new NameValueEntry("rider", "Jones") }, null, 2, true ); db.StreamAdd( - "race:italy", new NameValueEntry[]{new NameValueEntry("rider", "Wood")}, null, 2, true + "race:italy", new NameValueEntry[] { new NameValueEntry("rider", "Wood") }, null, 2, true ); db.StreamAdd( - "race:italy", new NameValueEntry[]{new NameValueEntry("rider", "Henshaw")}, null, 2, true + "race:italy", new NameValueEntry[] { new NameValueEntry("rider", "Henshaw") }, null, 2, true ); long res35 = db.StreamLength("race:italy"); @@ -624,7 +655,8 @@ string StreamConsumerInfoToString(StreamConsumerInfo info) { StreamEntry[] res36 = db.StreamRange("race:italy", "-", "+"); - foreach (StreamEntry entry in res36) { + foreach (StreamEntry entry in res36) + { Console.WriteLine(StreamEntryToString(entry)); } // >>> 1712758336128-0: [rider: Castilla] @@ -637,12 +669,13 @@ string StreamConsumerInfoToString(StreamConsumerInfo info) { // >>> 1712758342134-0: [rider: Henshaw] db.StreamAdd( - "race:italy", new NameValueEntry[]{new NameValueEntry("rider", "Smith")}, null, 2, false + "race:italy", new NameValueEntry[] { new NameValueEntry("rider", "Smith") }, null, 2, false ); StreamEntry[] res37 = db.StreamRange("race:italy", "-", "+"); - foreach (StreamEntry entry in res37) { + foreach (StreamEntry entry in res37) + { Console.WriteLine(StreamEntryToString(entry)); } // 1712758746476-1: [rider: Henshaw] @@ -680,18 +713,20 @@ string StreamConsumerInfoToString(StreamConsumerInfo info) { // STEP_START xdel StreamEntry[] res40 = db.StreamRange("race:italy", "-", "+"); - foreach (StreamEntry entry in res40) { + foreach (StreamEntry entry in res40) + { Console.WriteLine(StreamEntryToString(entry)); } // >>> 1712759694003-0: [rider: Henshaw] // >>> 1712759694003-1: [rider: Smith] - long res41 = db.StreamDelete("race:italy", new RedisValue[]{"1712759694003-1"}); + long res41 = db.StreamDelete("race:italy", new RedisValue[] { "1712759694003-1" }); Console.WriteLine(res41); // >>> 1 StreamEntry[] res42 = db.StreamRange("race:italy", "-", "+"); - foreach (StreamEntry entry in res42) { + foreach (StreamEntry entry in res42) + { Console.WriteLine(StreamEntryToString(entry)); } // >>> 1712759694003-0: [rider: Henshaw] @@ -703,7 +738,7 @@ string StreamConsumerInfoToString(StreamConsumerInfo info) { // REMOVE_END -// HIDE_START + // HIDE_START } } // HIDE_END From 51f4227f0688def561b5ddaa79f883fe732c0cbc Mon Sep 17 00:00:00 2001 From: Andy Stark Date: Fri, 12 Apr 2024 10:17:23 +0100 Subject: [PATCH 05/14] DOC-2646 added version check for feature --- tests/Doc/Stream_tutorial.cs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/tests/Doc/Stream_tutorial.cs b/tests/Doc/Stream_tutorial.cs index 22e0e362..2313983c 100644 --- a/tests/Doc/Stream_tutorial.cs +++ b/tests/Doc/Stream_tutorial.cs @@ -2,6 +2,7 @@ // HIDE_START using System.Diagnostics; +using System.Net; using System.Runtime.Serialization; using NRedisStack.Tests; using StackExchange.Redis; @@ -202,15 +203,19 @@ string StreamEntryToString(StreamEntry entry) // STEP_START xadd_7 - RedisValue res11 = db.StreamAdd( - "race:usa", - new NameValueEntry[]{ - new NameValueEntry("rider", "Norem") - }, - "0-*" - ); + RedisValue res11 = ""; + Version version = muxer.GetServer("localhost:6379").Version; + if (version.Major >= 7) { + res11 = db.StreamAdd( + "race:usa", + new NameValueEntry[]{ + new NameValueEntry("rider", "Norem") + }, + "0-*" + ); - Console.WriteLine(res11); // >>> "0-3" + Console.WriteLine(res11); // >>> "0-3" + } // STEP_END // Tests for 'xadd_7' step. From db0b4851d372b937641f37469199f8f963af85a3 Mon Sep 17 00:00:00 2001 From: Andy Stark Date: Fri, 12 Apr 2024 10:22:03 +0100 Subject: [PATCH 06/14] DOC-2646 dotnet format changes --- tests/Doc/Stream_tutorial.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/Doc/Stream_tutorial.cs b/tests/Doc/Stream_tutorial.cs index 2313983c..c7f6bc42 100644 --- a/tests/Doc/Stream_tutorial.cs +++ b/tests/Doc/Stream_tutorial.cs @@ -205,7 +205,8 @@ string StreamEntryToString(StreamEntry entry) // STEP_START xadd_7 RedisValue res11 = ""; Version version = muxer.GetServer("localhost:6379").Version; - if (version.Major >= 7) { + if (version.Major >= 7) + { res11 = db.StreamAdd( "race:usa", new NameValueEntry[]{ From cd0b89ac58eda7533a702ebfb976c846e03a2807 Mon Sep 17 00:00:00 2001 From: Andy Stark Date: Fri, 12 Apr 2024 10:33:40 +0100 Subject: [PATCH 07/14] DOC-2646 version check fix --- tests/Doc/Stream_tutorial.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/Doc/Stream_tutorial.cs b/tests/Doc/Stream_tutorial.cs index c7f6bc42..586590a2 100644 --- a/tests/Doc/Stream_tutorial.cs +++ b/tests/Doc/Stream_tutorial.cs @@ -221,7 +221,10 @@ string StreamEntryToString(StreamEntry entry) // Tests for 'xadd_7' step. // REMOVE_START - Assert.Equal("0-3", res11); + if (version.Major >= 7) + { + Assert.Equal("0-3", res11); + } // REMOVE_END From 07febbbb419136b8842ef8f25be051793ce6b5cb Mon Sep 17 00:00:00 2001 From: Andy Stark Date: Fri, 12 Apr 2024 10:55:19 +0100 Subject: [PATCH 08/14] DOC-2646 removed unused using statements --- tests/Doc/Stream_tutorial.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/Doc/Stream_tutorial.cs b/tests/Doc/Stream_tutorial.cs index 586590a2..ca8123f4 100644 --- a/tests/Doc/Stream_tutorial.cs +++ b/tests/Doc/Stream_tutorial.cs @@ -1,9 +1,6 @@ // EXAMPLE: stream_tutorial // HIDE_START -using System.Diagnostics; -using System.Net; -using System.Runtime.Serialization; using NRedisStack.Tests; using StackExchange.Redis; From 8dada2ac954bde45e1a2099d6047279aab20ec34 Mon Sep 17 00:00:00 2001 From: Andy Stark Date: Fri, 12 Apr 2024 11:10:14 +0100 Subject: [PATCH 09/14] DOC-2646 made string function static --- tests/Doc/Stream_tutorial.cs | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/tests/Doc/Stream_tutorial.cs b/tests/Doc/Stream_tutorial.cs index ca8123f4..b64a1691 100644 --- a/tests/Doc/Stream_tutorial.cs +++ b/tests/Doc/Stream_tutorial.cs @@ -14,6 +14,17 @@ namespace Doc; // HIDE_START public class Stream_tutorial { + static string StreamEntryToString(StreamEntry entry) + { + string[] values = new string[entry.Values.Length]; + + for (int i = 0; i < entry.Values.Length; i++) + { + values[i] = $"{entry.Values[i].Name}: {entry.Values[i].Value}"; + } + + return $"{entry.Id}: [{string.Join(", ", values)}]"; + } [SkipIfRedis(Is.OSSCluster)] public void run() @@ -71,18 +82,6 @@ public void run() // STEP_START xrange - string StreamEntryToString(StreamEntry entry) - { - string[] values = new string[entry.Values.Length]; - - for (int i = 0; i < entry.Values.Length; i++) - { - values[i] = $"{entry.Values[i].Name}: {entry.Values[i].Value}"; - } - - return $"{entry.Id}: [{string.Join(", ", values)}]"; - } - StreamEntry[] res4 = db.StreamRange("race:france", "1712668482289-0", "+", 2); foreach (StreamEntry entry in res4) From 2975a2a748f13e05c49c3b01c4f3cf3592c68dfc Mon Sep 17 00:00:00 2001 From: Andy Stark Date: Fri, 12 Apr 2024 11:29:04 +0100 Subject: [PATCH 10/14] DOC-2646 try to fix undefined attribute error --- tests/Doc/Stream_tutorial.cs | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/tests/Doc/Stream_tutorial.cs b/tests/Doc/Stream_tutorial.cs index b64a1691..0ae0f672 100644 --- a/tests/Doc/Stream_tutorial.cs +++ b/tests/Doc/Stream_tutorial.cs @@ -1,6 +1,7 @@ // EXAMPLE: stream_tutorial // HIDE_START +using System.Runtime.CompilerServices; using NRedisStack.Tests; using StackExchange.Redis; @@ -14,17 +15,6 @@ namespace Doc; // HIDE_START public class Stream_tutorial { - static string StreamEntryToString(StreamEntry entry) - { - string[] values = new string[entry.Values.Length]; - - for (int i = 0; i < entry.Values.Length; i++) - { - values[i] = $"{entry.Values[i].Name}: {entry.Values[i].Value}"; - } - - return $"{entry.Id}: [{string.Join(", ", values)}]"; - } [SkipIfRedis(Is.OSSCluster)] public void run() @@ -82,6 +72,18 @@ public void run() // STEP_START xrange + string StreamEntryToString(StreamEntry entry) + { + string[] values = new string[entry.Values.Length]; + + for (int i = 0; i < entry.Values.Length; i++) + { + values[i] = $"{entry.Values[i].Name}: {entry.Values[i].Value}"; + } + + return $"{entry.Id}: [{string.Join(", ", values)}]"; + } + StreamEntry[] res4 = db.StreamRange("race:france", "1712668482289-0", "+", 2); foreach (StreamEntry entry in res4) From a8f960d6cef427f7f65c4937c89290fe4a290cc2 Mon Sep 17 00:00:00 2001 From: Andy Stark Date: Fri, 12 Apr 2024 13:36:52 +0100 Subject: [PATCH 11/14] DOC-2646 changed doc test namespace --- tests/Doc/Stream_tutorial.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Doc/Stream_tutorial.cs b/tests/Doc/Stream_tutorial.cs index 0ae0f672..75c9c452 100644 --- a/tests/Doc/Stream_tutorial.cs +++ b/tests/Doc/Stream_tutorial.cs @@ -8,7 +8,7 @@ // HIDE_END // REMOVE_START -namespace Doc; +namespace NRedisStack.Doc; [Collection("DocsTests")] // REMOVE_END From 18728a0446b7c5c3d1a45929e3772d2905bb66cf Mon Sep 17 00:00:00 2001 From: Andy Stark Date: Fri, 12 Apr 2024 15:09:17 +0100 Subject: [PATCH 12/14] DOC-2646 replace custom string formatting functions --- tests/Doc/Stream_tutorial.cs | 111 +++++++++-------------------------- 1 file changed, 27 insertions(+), 84 deletions(-) diff --git a/tests/Doc/Stream_tutorial.cs b/tests/Doc/Stream_tutorial.cs index 75c9c452..7589301d 100644 --- a/tests/Doc/Stream_tutorial.cs +++ b/tests/Doc/Stream_tutorial.cs @@ -72,23 +72,11 @@ public void run() // STEP_START xrange - string StreamEntryToString(StreamEntry entry) - { - string[] values = new string[entry.Values.Length]; - - for (int i = 0; i < entry.Values.Length; i++) - { - values[i] = $"{entry.Values[i].Name}: {entry.Values[i].Value}"; - } - - return $"{entry.Id}: [{string.Join(", ", values)}]"; - } - StreamEntry[] res4 = db.StreamRange("race:france", "1712668482289-0", "+", 2); foreach (StreamEntry entry in res4) { - Console.WriteLine(StreamEntryToString(entry)); + Console.WriteLine($"{entry.Id}: [{string.Join(", ", entry.Values.Select(b=>$"{b.Name}: {b.Value}"))}]"); } // >>> 1712668482289-0: [rider: Castilla, speed: 30.199999999999999, position: 1, location_id: 1] @@ -106,7 +94,7 @@ string StreamEntryToString(StreamEntry entry) foreach (StreamEntry entry in res4) { - Console.WriteLine(StreamEntryToString(entry)); + Console.WriteLine($"{entry.Id}: [{string.Join(", ", entry.Values.Select(b=>$"{b.Name}: {b.Value}"))}]"); } // >>> 1712668482289-0: [rider: Castilla, speed: 30.199999999999999, position: 1, location_id: 1] @@ -231,7 +219,7 @@ string StreamEntryToString(StreamEntry entry) foreach (StreamEntry entry in res12) { - Console.WriteLine(StreamEntryToString(entry)); + Console.WriteLine($"{entry.Id}: [{string.Join(", ", entry.Values.Select(b=>$"{b.Name}: {b.Value}"))}]"); } // >>> 1712668482289-0: [rider: Castilla, speed: 30.199999999999999, position: 1, location_id: 1] // >>> 1712668766534-1: [rider: Norem, speed: 28.800000000000001, position: 3, location_id: 1] @@ -250,7 +238,7 @@ string StreamEntryToString(StreamEntry entry) foreach (StreamEntry entry in res13) { - Console.WriteLine(StreamEntryToString(entry)); + Console.WriteLine($"{entry.Id}: [{string.Join(", ", entry.Values.Select(b=>$"{b.Name}: {b.Value}"))}]"); } // >>> 1712668482289-0: [rider: Castilla, speed: 30.199999999999999, position: 1, location_id: 1] // STEP_END @@ -266,7 +254,7 @@ string StreamEntryToString(StreamEntry entry) foreach (StreamEntry entry in res14) { - Console.WriteLine(StreamEntryToString(entry)); + Console.WriteLine($"{entry.Id}: [{string.Join(", ", entry.Values.Select(b=>$"{b.Name}: {b.Value}"))}]"); } // >>> 1712668482289-0: [rider: Castilla, speed: 30.199999999999999, position: 1, location_id: 1] // >>> 1712668766534-1: [rider: Norem, speed: 28.800000000000001, position: 3, location_id: 1] @@ -283,7 +271,7 @@ string StreamEntryToString(StreamEntry entry) foreach (StreamEntry entry in res15) { - Console.WriteLine(StreamEntryToString(entry)); + Console.WriteLine($"{entry.Id}: [{string.Join(", ", entry.Values.Select(b=>$"{b.Name}: {b.Value}"))}]"); } // >>> 1712669055705-0: [rider: Prickett, speed: 29.699999999999999, position: 2, location_id: 1] // >>> 1712675674750-0: [rider: Castilla, speed: 29.899999999999999, position: 1, location_id: 2] @@ -300,7 +288,7 @@ string StreamEntryToString(StreamEntry entry) foreach (StreamEntry entry in res16) { - Console.WriteLine(StreamEntryToString(entry)); + Console.WriteLine($"{entry.Id}: [{string.Join(", ", entry.Values.Select(b=>$"{b.Name}: {b.Value}"))}]"); } // >>> // STEP_END @@ -316,7 +304,7 @@ string StreamEntryToString(StreamEntry entry) foreach (StreamEntry entry in res17) { - Console.WriteLine(StreamEntryToString(entry)); + Console.WriteLine($"{entry.Id}: [{string.Join(", ", entry.Values.Select(b=>$"{b.Name}: {b.Value}"))}]"); } // >>> 1712675674750-0: [rider: Castilla, speed: 29.899999999999999, position: 1, location_id: 2] // STEP_END @@ -332,7 +320,7 @@ string StreamEntryToString(StreamEntry entry) foreach (StreamEntry entry in res18) { - Console.WriteLine(StreamEntryToString(entry)); + Console.WriteLine($"{entry.Id}: [{string.Join(", ", entry.Values.Select(b=>$"{b.Name}: {b.Value}"))}]"); } // >>> 1712668482289-0: [rider: Castilla, speed: 30.199999999999999, position: 1, location_id: 1] // >>> 1712668766534-1: [rider: Norem, speed: 28.800000000000001, position: 3, location_id: 1] @@ -396,7 +384,7 @@ string StreamEntryToString(StreamEntry entry) foreach (StreamEntry entry in res21) { - Console.WriteLine(StreamEntryToString(entry)); + Console.WriteLine($"{entry.Id}: [{string.Join(", ", entry.Values.Select(b=>$"{b.Name}: {b.Value}"))}]"); } // >>> 1712744323758-0: [rider: Castilla] // STEP_END @@ -412,7 +400,7 @@ string StreamEntryToString(StreamEntry entry) foreach (StreamEntry entry in res22) { - Console.WriteLine(StreamEntryToString(entry)); + Console.WriteLine($"{entry.Id}: [{string.Join(", ", entry.Values.Select(b=>$"{b.Name}: {b.Value}"))}]"); // >>> 1712744323758-0: [rider: Castilla] } // STEP_END @@ -431,7 +419,7 @@ string StreamEntryToString(StreamEntry entry) foreach (StreamEntry entry in res24) { - Console.WriteLine(StreamEntryToString(entry)); + Console.WriteLine($"{entry.Id}: [{string.Join(", ", entry.Values.Select(b=>$"{b.Name}: {b.Value}"))}]"); } // >>> // STEP_END @@ -447,7 +435,7 @@ string StreamEntryToString(StreamEntry entry) foreach (StreamEntry entry in res25) { - Console.WriteLine(StreamEntryToString(entry)); + Console.WriteLine($"{entry.Id}: [{string.Join(", ", entry.Values.Select(b=>$"{b.Name}: {b.Value}"))}]"); } // >>> 1712744358384-0: [rider: Royce] // >>> 1712744379676-0: [rider: Sam-Bodden] @@ -460,21 +448,8 @@ string StreamEntryToString(StreamEntry entry) // STEP_START xpending - - string StreamPendingInfoToString(StreamPendingInfo info) - { - string[] consumerStrs = new string[info.Consumers.Length]; - - for (int i = 0; i < info.Consumers.Length; i++) - { - consumerStrs[i] = $"name: {info.Consumers[i].Name}, pending:{info.Consumers[i].PendingMessageCount}"; - } - - return $"pending: {info.PendingMessageCount}, min: {info.LowestPendingMessageId}, max: {info.HighestPendingMessageId}, consumers:[{string.Join(", ", consumerStrs)}]"; - } - StreamPendingInfo res26 = db.StreamPending("race:italy", "italy_riders"); - Console.WriteLine(StreamPendingInfoToString(res26)); + Console.WriteLine($"pending: {res26.PendingMessageCount}, min: {res26.LowestPendingMessageId}, max: {res26.HighestPendingMessageId}, consumers:[{string.Join(", ", res26.Consumers.Select(c=>$"{c.Name}: {c.PendingMessageCount}"))}]"); // >>> pending: 2, min: 1712747506906-0, max: 1712747506907-0, consumers:[name: Bob, pending:2] // STEP_END @@ -485,18 +460,13 @@ string StreamPendingInfoToString(StreamPendingInfo info) // STEP_START xpending_plus_minus - string StreamPendingMessageInfoToString(StreamPendingMessageInfo info) - { - return $"message_id: {info.MessageId}, consumer: {info.ConsumerName}, time_since_delivered: {info.IdleTimeInMilliseconds}, times_delivered: {info.DeliveryCount}"; - } - StreamPendingMessageInfo[] res27 = db.StreamPendingMessages( "race:italy", "italy_riders", 10, "", "-", "+" ); foreach (StreamPendingMessageInfo info in res27) { - Console.WriteLine(StreamPendingMessageInfoToString(info)); + Console.WriteLine($"message_id: {info.MessageId}, consumer: {info.ConsumerName}, time_since_delivered: {info.IdleTimeInMilliseconds}, times_delivered: {info.DeliveryCount}"); } // >>> message_id: min: 1712747506906-0, consumer: Bob, time_since_delivered: 31084, times_delivered: 1 // >>> message_id: min: 1712747506907-0, consumer: Bob, time_since_delivered: 31084, times_delivered: 1 @@ -513,7 +483,7 @@ string StreamPendingMessageInfoToString(StreamPendingMessageInfo info) foreach (StreamEntry entry in res28) { - Console.WriteLine(StreamEntryToString(entry)); + Console.WriteLine($"{entry.Id}: [{string.Join(", ", entry.Values.Select(b=>$"{b.Name}: {b.Value}"))}]"); } // >>> 1712744358384-0: [rider: Royce] // STEP_END @@ -531,7 +501,7 @@ string StreamPendingMessageInfoToString(StreamPendingMessageInfo info) foreach (StreamEntry entry in res29) { - Console.WriteLine(StreamEntryToString(entry)); + Console.WriteLine($"{entry.Id}: [{string.Join(", ", entry.Values.Select(b=>$"{b.Name}: {b.Value}"))}]"); } // >>> 1712744358384-0: [rider: Royce] // STEP_END @@ -541,25 +511,12 @@ string StreamPendingMessageInfoToString(StreamPendingMessageInfo info) // REMOVE_END - // STEP_START xautoclaim - string StreamAutoClaimResultToString(StreamAutoClaimResult result) - { - string[] claimedEntryStrings = new string[result.ClaimedEntries.Length]; - - for (int i = 0; i < claimedEntryStrings.Length; i++) - { - claimedEntryStrings[i] = StreamEntryToString(result.ClaimedEntries[i]); - } - - return $"{result.NextStartId}, ({string.Join(", ", claimedEntryStrings)})"; - } - StreamAutoClaimResult res30 = db.StreamAutoClaim( "race:italy", "italy_riders", "Alice", 1, "0-0", 1 ); - Console.WriteLine(StreamAutoClaimResultToString(res30)); + Console.WriteLine($"{res30.NextStartId}, ({string.Join(", ", res30.ClaimedEntries.Select(entry=>$"{entry.Id}: [{string.Join(", ", entry.Values.Select( b=>$"{b.Name}: {b.Value}"))}]" ))})"); // >>> 1712744379676-0, (1712744358384-0: [rider: Royce]) // STEP_END @@ -574,7 +531,7 @@ string StreamAutoClaimResultToString(StreamAutoClaimResult result) "race:italy", "italy_riders", "Alice", 1, "(1712744358384-0", 1 ); - Console.WriteLine(StreamAutoClaimResultToString(res31)); + Console.WriteLine($"{res31.NextStartId}, ({string.Join(", ", res31.ClaimedEntries.Select(entry=>$"{entry.Id}: [{string.Join(", ", entry.Values.Select( b=>$"{b.Name}: {b.Value}"))}]" ))})"); // >>> 0-0, (1712744379676-0: [rider: Sam-Bodden]) // STEP_END @@ -585,13 +542,8 @@ string StreamAutoClaimResultToString(StreamAutoClaimResult result) // STEP_START xinfo - string StreamInfoToString(StreamInfo info) - { - return $"length: {info.Length}, radix-tree-keys: {info.RadixTreeKeys}, radix-tree-nodes: {info.RadixTreeNodes}, last-generated-id: {info.LastGeneratedId}, first-entry: {StreamEntryToString(info.FirstEntry)}, last-entry: {StreamEntryToString(info.LastEntry)}"; - } - StreamInfo res32 = db.StreamInfo("race:italy"); - Console.WriteLine(StreamInfoToString(res32)); + Console.WriteLine($"length: {res32.Length}, radix-tree-keys: {res32.RadixTreeKeys}, radix-tree-nodes: {res32.RadixTreeNodes}, last-generated-id: {res32.LastGeneratedId}, first-entry: {$"{res32.FirstEntry.Id}: [{string.Join(", ", res32.FirstEntry.Values.Select(b=>$"{b.Name}: {b.Value}"))}]"}, last-entry: {$"{res32.LastEntry.Id}: [{string.Join(", ", res32.LastEntry.Values.Select(b=>$"{b.Name}: {b.Value}"))}]"}"); // >>> length: 5, radix-tree-keys: 1, radix-tree-nodes: 2, last-generated-id: 1712756762686-1, first-entry: 1712756762685-0: [rider: Castilla], last-entry: 1712756762686-1: [rider: Norem] // STEP_END @@ -602,16 +554,11 @@ string StreamInfoToString(StreamInfo info) // STEP_START xinfo_groups - string StreamGroupInfoToString(StreamGroupInfo info) - { - return $"name: {info.Name}, consumers: {info.ConsumerCount}, pending: {info.PendingMessageCount}, last-delivered-id: {info.LastDeliveredId}"; - } - StreamGroupInfo[] res33 = db.StreamGroupInfo("race:italy"); foreach (StreamGroupInfo info in res33) { - Console.WriteLine(StreamGroupInfoToString(info)); + Console.WriteLine($"name: {info.Name}, consumers: {info.ConsumerCount}, pending: {info.PendingMessageCount}, last-delivered-id: {info.LastDeliveredId}"); } // >>> name: italy_riders, consumers: 2, pending: 2, last-delivered-id: 1712757192730-2 // STEP_END @@ -623,16 +570,11 @@ string StreamGroupInfoToString(StreamGroupInfo info) // STEP_START xinfo_consumers - string StreamConsumerInfoToString(StreamConsumerInfo info) - { - return $"name: {info.Name}, pending: {info.PendingMessageCount}, idle: {info.IdleTimeInMilliseconds}"; - } - StreamConsumerInfo[] res34 = db.StreamConsumerInfo("race:italy", "italy_riders"); foreach (StreamConsumerInfo info in res34) { - Console.WriteLine(StreamConsumerInfoToString(info)); + Console.WriteLine($"name: {info.Name}, pending: {info.PendingMessageCount}, idle: {info.IdleTimeInMilliseconds}"); } // >>> name: Alice, pending: 1, idle: 7717 // >>> name: Bob, pending: 0, idle: 7722 @@ -664,7 +606,7 @@ string StreamConsumerInfoToString(StreamConsumerInfo info) foreach (StreamEntry entry in res36) { - Console.WriteLine(StreamEntryToString(entry)); + Console.WriteLine($"{entry.Id}: [{string.Join(", ", entry.Values.Select(b=>$"{b.Name}: {b.Value}"))}]"); } // >>> 1712758336128-0: [rider: Castilla] // >>> 1712758336128-1: [rider: Royce] @@ -683,7 +625,7 @@ string StreamConsumerInfoToString(StreamConsumerInfo info) foreach (StreamEntry entry in res37) { - Console.WriteLine(StreamEntryToString(entry)); + Console.WriteLine($"{entry.Id}: [{string.Join(", ", entry.Values.Select(b=>$"{b.Name}: {b.Value}"))}]"); } // 1712758746476-1: [rider: Henshaw] // 1712758746477-0: [rider: Smith] @@ -722,7 +664,7 @@ string StreamConsumerInfoToString(StreamConsumerInfo info) foreach (StreamEntry entry in res40) { - Console.WriteLine(StreamEntryToString(entry)); + Console.WriteLine($"{entry.Id}: [{string.Join(", ", entry.Values.Select(b=>$"{b.Name}: {b.Value}"))}]"); } // >>> 1712759694003-0: [rider: Henshaw] // >>> 1712759694003-1: [rider: Smith] @@ -734,7 +676,8 @@ string StreamConsumerInfoToString(StreamConsumerInfo info) foreach (StreamEntry entry in res42) { - Console.WriteLine(StreamEntryToString(entry)); + Console.WriteLine($"{entry.Id}: [{string.Join(", ", entry.Values.Select(b=>$"{b.Name}: {b.Value}"))}]"); + } // >>> 1712759694003-0: [rider: Henshaw] // STEP_END From a77f348f49c21194a061a70206d0ff5855683843 Mon Sep 17 00:00:00 2001 From: Andy Stark Date: Fri, 12 Apr 2024 15:21:34 +0100 Subject: [PATCH 13/14] DOC-2646 dotnet format --- tests/Doc/Stream_tutorial.cs | 46 ++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/tests/Doc/Stream_tutorial.cs b/tests/Doc/Stream_tutorial.cs index 7589301d..81a67a7e 100644 --- a/tests/Doc/Stream_tutorial.cs +++ b/tests/Doc/Stream_tutorial.cs @@ -76,7 +76,7 @@ public void run() foreach (StreamEntry entry in res4) { - Console.WriteLine($"{entry.Id}: [{string.Join(", ", entry.Values.Select(b=>$"{b.Name}: {b.Value}"))}]"); + Console.WriteLine($"{entry.Id}: [{string.Join(", ", entry.Values.Select(b => $"{b.Name}: {b.Value}"))}]"); } // >>> 1712668482289-0: [rider: Castilla, speed: 30.199999999999999, position: 1, location_id: 1] @@ -94,7 +94,7 @@ public void run() foreach (StreamEntry entry in res4) { - Console.WriteLine($"{entry.Id}: [{string.Join(", ", entry.Values.Select(b=>$"{b.Name}: {b.Value}"))}]"); + Console.WriteLine($"{entry.Id}: [{string.Join(", ", entry.Values.Select(b => $"{b.Name}: {b.Value}"))}]"); } // >>> 1712668482289-0: [rider: Castilla, speed: 30.199999999999999, position: 1, location_id: 1] @@ -219,7 +219,7 @@ public void run() foreach (StreamEntry entry in res12) { - Console.WriteLine($"{entry.Id}: [{string.Join(", ", entry.Values.Select(b=>$"{b.Name}: {b.Value}"))}]"); + Console.WriteLine($"{entry.Id}: [{string.Join(", ", entry.Values.Select(b => $"{b.Name}: {b.Value}"))}]"); } // >>> 1712668482289-0: [rider: Castilla, speed: 30.199999999999999, position: 1, location_id: 1] // >>> 1712668766534-1: [rider: Norem, speed: 28.800000000000001, position: 3, location_id: 1] @@ -238,7 +238,7 @@ public void run() foreach (StreamEntry entry in res13) { - Console.WriteLine($"{entry.Id}: [{string.Join(", ", entry.Values.Select(b=>$"{b.Name}: {b.Value}"))}]"); + Console.WriteLine($"{entry.Id}: [{string.Join(", ", entry.Values.Select(b => $"{b.Name}: {b.Value}"))}]"); } // >>> 1712668482289-0: [rider: Castilla, speed: 30.199999999999999, position: 1, location_id: 1] // STEP_END @@ -254,7 +254,7 @@ public void run() foreach (StreamEntry entry in res14) { - Console.WriteLine($"{entry.Id}: [{string.Join(", ", entry.Values.Select(b=>$"{b.Name}: {b.Value}"))}]"); + Console.WriteLine($"{entry.Id}: [{string.Join(", ", entry.Values.Select(b => $"{b.Name}: {b.Value}"))}]"); } // >>> 1712668482289-0: [rider: Castilla, speed: 30.199999999999999, position: 1, location_id: 1] // >>> 1712668766534-1: [rider: Norem, speed: 28.800000000000001, position: 3, location_id: 1] @@ -271,7 +271,7 @@ public void run() foreach (StreamEntry entry in res15) { - Console.WriteLine($"{entry.Id}: [{string.Join(", ", entry.Values.Select(b=>$"{b.Name}: {b.Value}"))}]"); + Console.WriteLine($"{entry.Id}: [{string.Join(", ", entry.Values.Select(b => $"{b.Name}: {b.Value}"))}]"); } // >>> 1712669055705-0: [rider: Prickett, speed: 29.699999999999999, position: 2, location_id: 1] // >>> 1712675674750-0: [rider: Castilla, speed: 29.899999999999999, position: 1, location_id: 2] @@ -288,7 +288,7 @@ public void run() foreach (StreamEntry entry in res16) { - Console.WriteLine($"{entry.Id}: [{string.Join(", ", entry.Values.Select(b=>$"{b.Name}: {b.Value}"))}]"); + Console.WriteLine($"{entry.Id}: [{string.Join(", ", entry.Values.Select(b => $"{b.Name}: {b.Value}"))}]"); } // >>> // STEP_END @@ -304,7 +304,7 @@ public void run() foreach (StreamEntry entry in res17) { - Console.WriteLine($"{entry.Id}: [{string.Join(", ", entry.Values.Select(b=>$"{b.Name}: {b.Value}"))}]"); + Console.WriteLine($"{entry.Id}: [{string.Join(", ", entry.Values.Select(b => $"{b.Name}: {b.Value}"))}]"); } // >>> 1712675674750-0: [rider: Castilla, speed: 29.899999999999999, position: 1, location_id: 2] // STEP_END @@ -320,7 +320,7 @@ public void run() foreach (StreamEntry entry in res18) { - Console.WriteLine($"{entry.Id}: [{string.Join(", ", entry.Values.Select(b=>$"{b.Name}: {b.Value}"))}]"); + Console.WriteLine($"{entry.Id}: [{string.Join(", ", entry.Values.Select(b => $"{b.Name}: {b.Value}"))}]"); } // >>> 1712668482289-0: [rider: Castilla, speed: 30.199999999999999, position: 1, location_id: 1] // >>> 1712668766534-1: [rider: Norem, speed: 28.800000000000001, position: 3, location_id: 1] @@ -384,7 +384,7 @@ public void run() foreach (StreamEntry entry in res21) { - Console.WriteLine($"{entry.Id}: [{string.Join(", ", entry.Values.Select(b=>$"{b.Name}: {b.Value}"))}]"); + Console.WriteLine($"{entry.Id}: [{string.Join(", ", entry.Values.Select(b => $"{b.Name}: {b.Value}"))}]"); } // >>> 1712744323758-0: [rider: Castilla] // STEP_END @@ -400,7 +400,7 @@ public void run() foreach (StreamEntry entry in res22) { - Console.WriteLine($"{entry.Id}: [{string.Join(", ", entry.Values.Select(b=>$"{b.Name}: {b.Value}"))}]"); + Console.WriteLine($"{entry.Id}: [{string.Join(", ", entry.Values.Select(b => $"{b.Name}: {b.Value}"))}]"); // >>> 1712744323758-0: [rider: Castilla] } // STEP_END @@ -419,7 +419,7 @@ public void run() foreach (StreamEntry entry in res24) { - Console.WriteLine($"{entry.Id}: [{string.Join(", ", entry.Values.Select(b=>$"{b.Name}: {b.Value}"))}]"); + Console.WriteLine($"{entry.Id}: [{string.Join(", ", entry.Values.Select(b => $"{b.Name}: {b.Value}"))}]"); } // >>> // STEP_END @@ -435,7 +435,7 @@ public void run() foreach (StreamEntry entry in res25) { - Console.WriteLine($"{entry.Id}: [{string.Join(", ", entry.Values.Select(b=>$"{b.Name}: {b.Value}"))}]"); + Console.WriteLine($"{entry.Id}: [{string.Join(", ", entry.Values.Select(b => $"{b.Name}: {b.Value}"))}]"); } // >>> 1712744358384-0: [rider: Royce] // >>> 1712744379676-0: [rider: Sam-Bodden] @@ -449,7 +449,7 @@ public void run() // STEP_START xpending StreamPendingInfo res26 = db.StreamPending("race:italy", "italy_riders"); - Console.WriteLine($"pending: {res26.PendingMessageCount}, min: {res26.LowestPendingMessageId}, max: {res26.HighestPendingMessageId}, consumers:[{string.Join(", ", res26.Consumers.Select(c=>$"{c.Name}: {c.PendingMessageCount}"))}]"); + Console.WriteLine($"pending: {res26.PendingMessageCount}, min: {res26.LowestPendingMessageId}, max: {res26.HighestPendingMessageId}, consumers:[{string.Join(", ", res26.Consumers.Select(c => $"{c.Name}: {c.PendingMessageCount}"))}]"); // >>> pending: 2, min: 1712747506906-0, max: 1712747506907-0, consumers:[name: Bob, pending:2] // STEP_END @@ -483,7 +483,7 @@ public void run() foreach (StreamEntry entry in res28) { - Console.WriteLine($"{entry.Id}: [{string.Join(", ", entry.Values.Select(b=>$"{b.Name}: {b.Value}"))}]"); + Console.WriteLine($"{entry.Id}: [{string.Join(", ", entry.Values.Select(b => $"{b.Name}: {b.Value}"))}]"); } // >>> 1712744358384-0: [rider: Royce] // STEP_END @@ -501,7 +501,7 @@ public void run() foreach (StreamEntry entry in res29) { - Console.WriteLine($"{entry.Id}: [{string.Join(", ", entry.Values.Select(b=>$"{b.Name}: {b.Value}"))}]"); + Console.WriteLine($"{entry.Id}: [{string.Join(", ", entry.Values.Select(b => $"{b.Name}: {b.Value}"))}]"); } // >>> 1712744358384-0: [rider: Royce] // STEP_END @@ -516,7 +516,7 @@ public void run() "race:italy", "italy_riders", "Alice", 1, "0-0", 1 ); - Console.WriteLine($"{res30.NextStartId}, ({string.Join(", ", res30.ClaimedEntries.Select(entry=>$"{entry.Id}: [{string.Join(", ", entry.Values.Select( b=>$"{b.Name}: {b.Value}"))}]" ))})"); + Console.WriteLine($"{res30.NextStartId}, ({string.Join(", ", res30.ClaimedEntries.Select(entry => $"{entry.Id}: [{string.Join(", ", entry.Values.Select(b => $"{b.Name}: {b.Value}"))}]"))})"); // >>> 1712744379676-0, (1712744358384-0: [rider: Royce]) // STEP_END @@ -531,7 +531,7 @@ public void run() "race:italy", "italy_riders", "Alice", 1, "(1712744358384-0", 1 ); - Console.WriteLine($"{res31.NextStartId}, ({string.Join(", ", res31.ClaimedEntries.Select(entry=>$"{entry.Id}: [{string.Join(", ", entry.Values.Select( b=>$"{b.Name}: {b.Value}"))}]" ))})"); + Console.WriteLine($"{res31.NextStartId}, ({string.Join(", ", res31.ClaimedEntries.Select(entry => $"{entry.Id}: [{string.Join(", ", entry.Values.Select(b => $"{b.Name}: {b.Value}"))}]"))})"); // >>> 0-0, (1712744379676-0: [rider: Sam-Bodden]) // STEP_END @@ -543,7 +543,7 @@ public void run() // STEP_START xinfo StreamInfo res32 = db.StreamInfo("race:italy"); - Console.WriteLine($"length: {res32.Length}, radix-tree-keys: {res32.RadixTreeKeys}, radix-tree-nodes: {res32.RadixTreeNodes}, last-generated-id: {res32.LastGeneratedId}, first-entry: {$"{res32.FirstEntry.Id}: [{string.Join(", ", res32.FirstEntry.Values.Select(b=>$"{b.Name}: {b.Value}"))}]"}, last-entry: {$"{res32.LastEntry.Id}: [{string.Join(", ", res32.LastEntry.Values.Select(b=>$"{b.Name}: {b.Value}"))}]"}"); + Console.WriteLine($"length: {res32.Length}, radix-tree-keys: {res32.RadixTreeKeys}, radix-tree-nodes: {res32.RadixTreeNodes}, last-generated-id: {res32.LastGeneratedId}, first-entry: {$"{res32.FirstEntry.Id}: [{string.Join(", ", res32.FirstEntry.Values.Select(b => $"{b.Name}: {b.Value}"))}]"}, last-entry: {$"{res32.LastEntry.Id}: [{string.Join(", ", res32.LastEntry.Values.Select(b => $"{b.Name}: {b.Value}"))}]"}"); // >>> length: 5, radix-tree-keys: 1, radix-tree-nodes: 2, last-generated-id: 1712756762686-1, first-entry: 1712756762685-0: [rider: Castilla], last-entry: 1712756762686-1: [rider: Norem] // STEP_END @@ -606,7 +606,7 @@ public void run() foreach (StreamEntry entry in res36) { - Console.WriteLine($"{entry.Id}: [{string.Join(", ", entry.Values.Select(b=>$"{b.Name}: {b.Value}"))}]"); + Console.WriteLine($"{entry.Id}: [{string.Join(", ", entry.Values.Select(b => $"{b.Name}: {b.Value}"))}]"); } // >>> 1712758336128-0: [rider: Castilla] // >>> 1712758336128-1: [rider: Royce] @@ -625,7 +625,7 @@ public void run() foreach (StreamEntry entry in res37) { - Console.WriteLine($"{entry.Id}: [{string.Join(", ", entry.Values.Select(b=>$"{b.Name}: {b.Value}"))}]"); + Console.WriteLine($"{entry.Id}: [{string.Join(", ", entry.Values.Select(b => $"{b.Name}: {b.Value}"))}]"); } // 1712758746476-1: [rider: Henshaw] // 1712758746477-0: [rider: Smith] @@ -664,7 +664,7 @@ public void run() foreach (StreamEntry entry in res40) { - Console.WriteLine($"{entry.Id}: [{string.Join(", ", entry.Values.Select(b=>$"{b.Name}: {b.Value}"))}]"); + Console.WriteLine($"{entry.Id}: [{string.Join(", ", entry.Values.Select(b => $"{b.Name}: {b.Value}"))}]"); } // >>> 1712759694003-0: [rider: Henshaw] // >>> 1712759694003-1: [rider: Smith] @@ -676,7 +676,7 @@ public void run() foreach (StreamEntry entry in res42) { - Console.WriteLine($"{entry.Id}: [{string.Join(", ", entry.Values.Select(b=>$"{b.Name}: {b.Value}"))}]"); + Console.WriteLine($"{entry.Id}: [{string.Join(", ", entry.Values.Select(b => $"{b.Name}: {b.Value}"))}]"); } // >>> 1712759694003-0: [rider: Henshaw] From 2e0d4f4900eed23dc358c2bae26724193432ab15 Mon Sep 17 00:00:00 2001 From: shacharPash Date: Sun, 14 Apr 2024 14:45:09 +0300 Subject: [PATCH 14/14] change class name to StreamTutorial --- tests/Doc/{Stream_tutorial.cs => StreamTutorial.cs} | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) rename tests/Doc/{Stream_tutorial.cs => StreamTutorial.cs} (99%) diff --git a/tests/Doc/Stream_tutorial.cs b/tests/Doc/StreamTutorial.cs similarity index 99% rename from tests/Doc/Stream_tutorial.cs rename to tests/Doc/StreamTutorial.cs index 81a67a7e..db37b928 100644 --- a/tests/Doc/Stream_tutorial.cs +++ b/tests/Doc/StreamTutorial.cs @@ -13,7 +13,7 @@ namespace NRedisStack.Doc; // REMOVE_END // HIDE_START -public class Stream_tutorial +public class StreamTutorial { [SkipIfRedis(Is.OSSCluster)] @@ -98,7 +98,7 @@ public void run() } // >>> 1712668482289-0: [rider: Castilla, speed: 30.199999999999999, position: 1, location_id: 1] - // >>> 1712668766534-1: [rider: Norem, speed: 28.800000000000001, position: 3, location_id: 1] + // >>> 1712668766534-1: [rider: Norem, speed: 28.800000000000001, position: 3, location_id: 1] // >>> 1712669055705-0: [rider: Prickett, speed: 29.699999999999999, position: 2, location_id: 1] // STEP_END @@ -648,7 +648,7 @@ public void run() // REMOVE_END - // STEP_START xtrim2 + // STEP_START xtrim2 long res39 = db.StreamTrim("race:italy", 10, true); Console.WriteLine(res39); // >>> 0 // STEP_END