@@ -2585,7 +2585,7 @@ 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
+ Set6 * numberStruct `redis:"set6,omitempty"`
2589
2589
}
2590
2590
2591
2591
hSet = client .HSet (ctx , "hash3" , & setOmitEmpty {
@@ -2598,6 +2598,7 @@ var _ = Describe("Commands", func() {
2598
2598
Expect (hGetAll .Err ()).NotTo (HaveOccurred ())
2599
2599
Expect (hGetAll .Val ()).To (Equal (map [string ]string {
2600
2600
"set1" : "val" ,
2601
+ "set6" : `{"Number":0}` ,
2601
2602
}))
2602
2603
var hash3 setOmitEmpty
2603
2604
Expect (hGetAll .Scan (& hash3 )).NotTo (HaveOccurred ())
@@ -2606,13 +2607,12 @@ var _ = Describe("Commands", func() {
2606
2607
Expect (hash3 .Set3 ).To (Equal (time .Duration (0 )))
2607
2608
Expect (hash3 .Set4 ).To (Equal ("" ))
2608
2609
Expect (hash3 .Set5 ).To (Equal (time.Time {}))
2609
- Expect (hash3 .Set6 ).To (Equal (childStruct {}))
2610
+ Expect (hash3 .Set6 ).To (Equal (numberStruct {}))
2610
2611
2611
- now := time .Now ()
2612
2612
hSet = client .HSet (ctx , "hash4" , setOmitEmpty {
2613
2613
Set1 : "val" ,
2614
- Set6 : childStruct {
2615
- Date : now ,
2614
+ Set6 : & numberStruct {
2615
+ Number : 5 ,
2616
2616
},
2617
2617
})
2618
2618
Expect (hSet .Err ()).NotTo (HaveOccurred ())
@@ -2622,7 +2622,7 @@ var _ = Describe("Commands", func() {
2622
2622
Expect (hGetAll .Err ()).NotTo (HaveOccurred ())
2623
2623
Expect (hGetAll .Val ()).To (Equal (map [string ]string {
2624
2624
"set1" : "val" ,
2625
- "set6" : fmt . Sprintf ( "{ \" Date \" : \" %s \" }" , now . Format ( time . RFC3339Nano )) ,
2625
+ "set6" : `{"Number":5}` ,
2626
2626
}))
2627
2627
})
2628
2628
@@ -7665,12 +7665,16 @@ type numberStruct struct {
7665
7665
Number int
7666
7666
}
7667
7667
7668
- func (s * numberStruct ) MarshalBinary () ([]byte , error ) {
7669
- return json .Marshal (s )
7668
+ func (n * numberStruct ) MarshalBinary () ([]byte , error ) {
7669
+ return json .Marshal (n )
7670
+ }
7671
+
7672
+ func (n * numberStruct ) UnmarshalBinary (b []byte ) error {
7673
+ return json .Unmarshal (b , n )
7670
7674
}
7671
7675
7672
- func (s * numberStruct ) UnmarshalBinary ( b [] byte ) error {
7673
- return json .Unmarshal (b , s )
7676
+ func (n * numberStruct ) ScanRedis ( str string ) error {
7677
+ return json .Unmarshal ([] byte ( str ), n )
7674
7678
}
7675
7679
7676
7680
func deref (viface interface {}) interface {} {
@@ -7680,15 +7684,3 @@ func deref(viface interface{}) interface{} {
7680
7684
}
7681
7685
return v .Interface ()
7682
7686
}
7683
-
7684
- type childStruct struct {
7685
- Date time.Time `redis:"date,omitempty"`
7686
- }
7687
-
7688
- func (c childStruct ) MarshalBinary () ([]byte , error ) {
7689
- return json .Marshal (& c )
7690
- }
7691
-
7692
- func (c childStruct ) UnmarshalBinary (data []byte ) error {
7693
- return json .Unmarshal (data , & c )
7694
- }
0 commit comments