@@ -2585,20 +2585,45 @@ var _ = Describe("Commands", func() {
2585
2585
Set3 time.Duration `redis:"set3,omitempty"`
2586
2586
Set4 string `redis:"set4,omitempty"`
2587
2587
Set5 time.Time `redis:"set5,omitempty"`
2588
+ Set6 childStruct `redis:"set6,omitempty"`
2588
2589
}
2590
+
2589
2591
hSet = client .HSet (ctx , "hash3" , & setOmitEmpty {
2590
2592
Set1 : "val" ,
2591
2593
})
2592
2594
Expect (hSet .Err ()).NotTo (HaveOccurred ())
2593
2595
Expect (hSet .Val ()).To (Equal (int64 (1 )))
2594
2596
2595
- var dest setOmitEmpty
2596
2597
hGetAll := client .HGetAll (ctx , "hash3" )
2597
2598
Expect (hGetAll .Err ()).NotTo (HaveOccurred ())
2598
2599
Expect (hGetAll .Val ()).To (Equal (map [string ]string {
2599
2600
"set1" : "val" ,
2600
2601
}))
2601
- Expect (hGetAll .Scan (& dest )).NotTo (HaveOccurred ())
2602
+ var hash3 setOmitEmpty
2603
+ Expect (hGetAll .Scan (& hash3 )).NotTo (HaveOccurred ())
2604
+ Expect (hash3 .Set1 ).To (Equal ("val" ))
2605
+ Expect (hash3 .Set2 ).To (Equal (0 ))
2606
+ Expect (hash3 .Set3 ).To (Equal (time .Duration (0 )))
2607
+ Expect (hash3 .Set4 ).To (Equal ("" ))
2608
+ Expect (hash3 .Set5 ).To (Equal (time.Time {}))
2609
+ Expect (hash3 .Set6 ).To (Equal (childStruct {}))
2610
+
2611
+ now := time .Now ()
2612
+ hSet = client .HSet (ctx , "hash4" , setOmitEmpty {
2613
+ Set1 : "val" ,
2614
+ Set6 : childStruct {
2615
+ Date : now ,
2616
+ },
2617
+ })
2618
+ Expect (hSet .Err ()).NotTo (HaveOccurred ())
2619
+ Expect (hSet .Val ()).To (Equal (int64 (2 )))
2620
+
2621
+ hGetAll = client .HGetAll (ctx , "hash4" )
2622
+ Expect (hGetAll .Err ()).NotTo (HaveOccurred ())
2623
+ Expect (hGetAll .Val ()).To (Equal (map [string ]string {
2624
+ "set1" : "val" ,
2625
+ "set6" : fmt .Sprintf ("{\" Date\" :\" %s\" }" , now .Format (time .RFC3339Nano )),
2626
+ }))
2602
2627
})
2603
2628
2604
2629
It ("should HSetNX" , func () {
@@ -7633,3 +7658,15 @@ func deref(viface interface{}) interface{} {
7633
7658
}
7634
7659
return v .Interface ()
7635
7660
}
7661
+
7662
+ type childStruct struct {
7663
+ Date time.Time `redis:"date,omitempty"`
7664
+ }
7665
+
7666
+ func (c childStruct ) MarshalBinary () ([]byte , error ) {
7667
+ return json .Marshal (& c )
7668
+ }
7669
+
7670
+ func (c childStruct ) UnmarshalBinary (data []byte ) error {
7671
+ return json .Unmarshal (data , & c )
7672
+ }
0 commit comments