From 8c43317ed9ff2b8ce3b4957844c3068ff8912dc1 Mon Sep 17 00:00:00 2001 From: Andy Stark Date: Tue, 14 Jan 2025 14:05:06 +0000 Subject: [PATCH 1/2] DOC-4448 code examples for hgetall and hvals --- tests/Doc/CmdsHashExample.cs | 41 +++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/tests/Doc/CmdsHashExample.cs b/tests/Doc/CmdsHashExample.cs index 40036e15..af9ef445 100644 --- a/tests/Doc/CmdsHashExample.cs +++ b/tests/Doc/CmdsHashExample.cs @@ -35,6 +35,7 @@ public void run() RedisValue res3 = db.HashGet("myhash", "field2"); Console.WriteLine(res3); // >>> Null + // STEP_END // Tests for 'hget' step. @@ -67,6 +68,7 @@ public void run() HashEntry[] res8 = db.HashGetAll("myhash"); Console.WriteLine($"{string.Join(", ", res8.Select(h => $"{h.Name}: {h.Value}"))}"); // >>> field1: Hello, field2: Hi, field3: World + // STEP_END // Tests for 'hset' step. @@ -79,9 +81,46 @@ public void run() "field1: Hello, field2: Hi, field3: World", string.Join(", ", res8.Select(h => $"{h.Name}: {h.Value}")) ); + db.KeyDelete("myhash"); + // REMOVE_END + + // STEP_START hgetall + db.HashSet("myhash", + new HashEntry[] { + new HashEntry("field1", "Hello"), + new HashEntry("field2", "World") + } + ); + + HashEntry[] hGetAllResult = db.HashGetAll("myhash"); + Array.Sort(hGetAllResult, (a1, a2) => a1.Name.CompareTo(a2.Name)); + Console.WriteLine( + string.Join(", ", hGetAllResult.Select(e => $"{e.Name}: {e.Value}")) + ); + // >>> field1: Hello, field2: World + // STEP_END + // REMOVE_START + Assert.Equal("field1: Hello, field2: World", string.Join(", ", hGetAllResult.Select(e => $"{e.Name}: {e.Value}"))); + db.KeyDelete("myhash"); + // REMOVE_END + + // STEP_START hvals + db.HashSet("myhash", + new HashEntry[] { + new HashEntry("field1", "Hello"), + new HashEntry("field2", "World") + } + ); + + RedisValue[] hValsResult = db.HashValues("myhash"); + Array.Sort(hValsResult); + Console.WriteLine(string.Join(", ", hValsResult)); + // >>> Hello, World + // STEP_END + // REMOVE_START + Assert.Equal("Hello, World", string.Join(", ", hValsResult)); // REMOVE_END // HIDE_START } } // HIDE_END - From fff9dcbd9198b6a9a31f3ffd05e45c71e528d817 Mon Sep 17 00:00:00 2001 From: Andy Stark Date: Tue, 14 Jan 2025 14:38:03 +0000 Subject: [PATCH 2/2] DOC-4448 tidied final example formatting --- tests/Doc/CmdsHashExample.cs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/tests/Doc/CmdsHashExample.cs b/tests/Doc/CmdsHashExample.cs index af9ef445..977e8ae6 100644 --- a/tests/Doc/CmdsHashExample.cs +++ b/tests/Doc/CmdsHashExample.cs @@ -1,12 +1,10 @@ // EXAMPLE: cmds_hash // HIDE_START - -using NRedisStack.Tests; using StackExchange.Redis; - // HIDE_END - // REMOVE_START +using NRedisStack.Tests; + namespace Doc; [Collection("DocsTests")] // REMOVE_END @@ -26,7 +24,6 @@ public void run() //REMOVE_END // HIDE_END - // STEP_START hget bool res1 = db.HashSet("myhash", "field1", "foo"); @@ -37,8 +34,6 @@ public void run() Console.WriteLine(res3); // >>> Null // STEP_END - - // Tests for 'hget' step. // REMOVE_START Assert.True(res1); Assert.Equal("foo", res2); @@ -70,8 +65,6 @@ public void run() // >>> field1: Hello, field2: Hi, field3: World // STEP_END - - // Tests for 'hset' step. // REMOVE_START Assert.True(res4); Assert.Equal("Hello", res5);