1
1
// EXAMPLE: cmds_hash
2
2
// HIDE_START
3
-
4
- using NRedisStack . Tests ;
5
3
using StackExchange . Redis ;
6
-
7
4
// HIDE_END
8
-
9
5
// REMOVE_START
6
+ using NRedisStack . Tests ;
7
+
10
8
namespace Doc ;
11
9
[ Collection ( "DocsTests" ) ]
12
10
// REMOVE_END
@@ -26,7 +24,6 @@ public void run()
26
24
//REMOVE_END
27
25
// HIDE_END
28
26
29
-
30
27
// STEP_START hget
31
28
bool res1 = db . HashSet ( "myhash" , "field1" , "foo" ) ;
32
29
@@ -35,9 +32,8 @@ public void run()
35
32
36
33
RedisValue res3 = db . HashGet ( "myhash" , "field2" ) ;
37
34
Console . WriteLine ( res3 ) ; // >>> Null
38
- // STEP_END
39
35
40
- // Tests for 'hget' step.
36
+ // STEP_END
41
37
// REMOVE_START
42
38
Assert . True ( res1 ) ;
43
39
Assert . Equal ( "foo" , res2 ) ;
@@ -67,9 +63,8 @@ public void run()
67
63
HashEntry [ ] res8 = db . HashGetAll ( "myhash" ) ;
68
64
Console . WriteLine ( $ "{ string . Join ( ", " , res8 . Select ( h => $ "{ h . Name } : { h . Value } ") ) } ") ;
69
65
// >>> field1: Hello, field2: Hi, field3: World
70
- // STEP_END
71
66
72
- // Tests for 'hset' step.
67
+ // STEP_END
73
68
// REMOVE_START
74
69
Assert . True ( res4 ) ;
75
70
Assert . Equal ( "Hello" , res5 ) ;
@@ -79,9 +74,46 @@ public void run()
79
74
"field1: Hello, field2: Hi, field3: World" ,
80
75
string . Join ( ", " , res8 . Select ( h => $ "{ h . Name } : { h . Value } ") )
81
76
) ;
77
+ db . KeyDelete ( "myhash" ) ;
78
+ // REMOVE_END
79
+
80
+ // STEP_START hgetall
81
+ db . HashSet ( "myhash" ,
82
+ new HashEntry [ ] {
83
+ new HashEntry ( "field1" , "Hello" ) ,
84
+ new HashEntry ( "field2" , "World" )
85
+ }
86
+ ) ;
87
+
88
+ HashEntry [ ] hGetAllResult = db . HashGetAll ( "myhash" ) ;
89
+ Array . Sort ( hGetAllResult , ( a1 , a2 ) => a1 . Name . CompareTo ( a2 . Name ) ) ;
90
+ Console . WriteLine (
91
+ string . Join ( ", " , hGetAllResult . Select ( e => $ "{ e . Name } : { e . Value } ") )
92
+ ) ;
93
+ // >>> field1: Hello, field2: World
94
+ // STEP_END
95
+ // REMOVE_START
96
+ Assert . Equal ( "field1: Hello, field2: World" , string . Join ( ", " , hGetAllResult . Select ( e => $ "{ e . Name } : { e . Value } ") ) ) ;
97
+ db . KeyDelete ( "myhash" ) ;
98
+ // REMOVE_END
99
+
100
+ // STEP_START hvals
101
+ db . HashSet ( "myhash" ,
102
+ new HashEntry [ ] {
103
+ new HashEntry ( "field1" , "Hello" ) ,
104
+ new HashEntry ( "field2" , "World" )
105
+ }
106
+ ) ;
107
+
108
+ RedisValue [ ] hValsResult = db . HashValues ( "myhash" ) ;
109
+ Array . Sort ( hValsResult ) ;
110
+ Console . WriteLine ( string . Join ( ", " , hValsResult ) ) ;
111
+ // >>> Hello, World
112
+ // STEP_END
113
+ // REMOVE_START
114
+ Assert . Equal ( "Hello, World" , string . Join ( ", " , hValsResult ) ) ;
82
115
// REMOVE_END
83
116
// HIDE_START
84
117
}
85
118
}
86
119
// HIDE_END
87
-
0 commit comments