Skip to content

Commit 8c43317

Browse files
DOC-4448 code examples for hgetall and hvals
1 parent f63bf4a commit 8c43317

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

tests/Doc/CmdsHashExample.cs

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public void run()
3535

3636
RedisValue res3 = db.HashGet("myhash", "field2");
3737
Console.WriteLine(res3); // >>> Null
38+
3839
// STEP_END
3940

4041
// Tests for 'hget' step.
@@ -67,6 +68,7 @@ public void run()
6768
HashEntry[] res8 = db.HashGetAll("myhash");
6869
Console.WriteLine($"{string.Join(", ", res8.Select(h => $"{h.Name}: {h.Value}"))}");
6970
// >>> field1: Hello, field2: Hi, field3: World
71+
7072
// STEP_END
7173

7274
// Tests for 'hset' step.
@@ -79,9 +81,46 @@ public void run()
7981
"field1: Hello, field2: Hi, field3: World",
8082
string.Join(", ", res8.Select(h => $"{h.Name}: {h.Value}"))
8183
);
84+
db.KeyDelete("myhash");
85+
// REMOVE_END
86+
87+
// STEP_START hgetall
88+
db.HashSet("myhash",
89+
new HashEntry[] {
90+
new HashEntry("field1", "Hello"),
91+
new HashEntry("field2", "World")
92+
}
93+
);
94+
95+
HashEntry[] hGetAllResult = db.HashGetAll("myhash");
96+
Array.Sort(hGetAllResult, (a1, a2) => a1.Name.CompareTo(a2.Name));
97+
Console.WriteLine(
98+
string.Join(", ", hGetAllResult.Select(e => $"{e.Name}: {e.Value}"))
99+
);
100+
// >>> field1: Hello, field2: World
101+
// STEP_END
102+
// REMOVE_START
103+
Assert.Equal("field1: Hello, field2: World", string.Join(", ", hGetAllResult.Select(e => $"{e.Name}: {e.Value}")));
104+
db.KeyDelete("myhash");
105+
// REMOVE_END
106+
107+
// STEP_START hvals
108+
db.HashSet("myhash",
109+
new HashEntry[] {
110+
new HashEntry("field1", "Hello"),
111+
new HashEntry("field2", "World")
112+
}
113+
);
114+
115+
RedisValue[] hValsResult = db.HashValues("myhash");
116+
Array.Sort(hValsResult);
117+
Console.WriteLine(string.Join(", ", hValsResult));
118+
// >>> Hello, World
119+
// STEP_END
120+
// REMOVE_START
121+
Assert.Equal("Hello, World", string.Join(", ", hValsResult));
82122
// REMOVE_END
83123
// HIDE_START
84124
}
85125
}
86126
// HIDE_END
87-

0 commit comments

Comments
 (0)