File tree Expand file tree Collapse file tree 3 files changed +67
-1
lines changed
Expand file tree Collapse file tree 3 files changed +67
-1
lines changed Original file line number Diff line number Diff line change @@ -92,6 +92,10 @@ crate-type = ["cdylib"]
9292name = " info_handler_struct"
9393crate-type = [" cdylib" ]
9494
95+ [[example ]]
96+ name = " info_handler_multiple_sections"
97+ crate-type = [" cdylib" ]
98+
9599[[example ]]
96100name = " info"
97101crate-type = [" cdylib" ]
Original file line number Diff line number Diff line change 1+ use std:: collections:: HashMap ;
2+
3+ use redis_module:: InfoContext ;
4+ use redis_module:: { redis_module, RedisResult } ;
5+ use redis_module_macros:: { info_command_handler, InfoSection } ;
6+
7+ #[ derive( Debug , Clone , InfoSection ) ]
8+ struct InfoSection1 {
9+ field_1 : String ,
10+ }
11+
12+ #[ derive( Debug , Clone , InfoSection ) ]
13+ struct InfoSection2 {
14+ field_2 : String ,
15+ }
16+
17+ #[ info_command_handler]
18+ fn add_info ( ctx : & InfoContext , _for_crash_report : bool ) -> RedisResult < ( ) > {
19+ let data = InfoSection1 {
20+ field_1 : "value1" . to_owned ( ) ,
21+ } ;
22+ let _ = ctx. build_one_section ( data) ;
23+
24+ let data = InfoSection2 {
25+ field_2 : "value2" . to_owned ( ) ,
26+ } ;
27+
28+ ctx. build_one_section ( data)
29+ }
30+
31+ //////////////////////////////////////////////////////
32+
33+ redis_module ! {
34+ name: "info_handler_multiple_sections" ,
35+ version: 1 ,
36+ allocator: ( redis_module:: alloc:: RedisAlloc , redis_module:: alloc:: RedisAlloc ) ,
37+ data_types: [ ] ,
38+ commands: [ ] ,
39+ }
Original file line number Diff line number Diff line change @@ -133,7 +133,7 @@ fn test_helper_info() -> Result<()> {
133133 . arg ( module)
134134 . query ( & mut con)
135135 . with_context ( || format ! ( "failed to run INFO {module}" ) ) ?;
136- println ! ( "Now processing {module}. Result: {res}." ) ;
136+
137137 assert ! ( res. contains( & format!( "{module}_field:value" ) ) ) ;
138138 if has_dictionary {
139139 assert ! ( res. contains( "dictionary:key=value" ) ) ;
@@ -143,6 +143,29 @@ fn test_helper_info() -> Result<()> {
143143 } )
144144}
145145
146+ #[ test]
147+ fn test_info_handler_multiple_sections ( ) -> Result < ( ) > {
148+ const MODULES : [ & str ; 1 ] = [ "info_handler_multiple_sections" ] ;
149+
150+ MODULES . into_iter ( ) . try_for_each ( |module| {
151+ let port: u16 = 6500 ;
152+ let _guards = vec ! [ start_redis_server_with_module( module, port)
153+ . with_context( || "failed to start redis server" ) ?] ;
154+ let mut con =
155+ get_redis_connection ( port) . with_context ( || "failed to connect to redis server" ) ?;
156+
157+ let res: String = redis:: cmd ( "INFO" )
158+ . arg ( format ! ( "{module}_InfoSection2" ) )
159+ . query ( & mut con)
160+ . with_context ( || format ! ( "failed to run INFO {module}" ) ) ?;
161+
162+ assert ! ( res. contains( & format!( "{module}_field_2:value2" ) ) ) ;
163+ assert ! ( !res. contains( & format!( "{module}_field_1:value1" ) ) ) ;
164+
165+ Ok ( ( ) )
166+ } )
167+ }
168+
146169#[ allow( unused_must_use) ]
147170#[ test]
148171fn test_test_helper_err ( ) -> Result < ( ) > {
You can’t perform that action at this time.
0 commit comments