@@ -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 {
@@ -2606,23 +2606,25 @@ var _ = Describe("Commands", func() {
2606
2606
Expect (hash3 .Set3 ).To (Equal (time .Duration (0 )))
2607
2607
Expect (hash3 .Set4 ).To (Equal ("" ))
2608
2608
Expect (hash3 .Set5 ).To (Equal (time.Time {}))
2609
- Expect (hash3 .Set6 ).To (Equal ( childStruct {} ))
2609
+ Expect (hash3 .Set6 ).To (BeNil ( ))
2610
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
+ Set5 : now ,
2615
+ Set6 : & numberStruct {
2616
+ Number : 5 ,
2616
2617
},
2617
2618
})
2618
2619
Expect (hSet .Err ()).NotTo (HaveOccurred ())
2619
- Expect (hSet .Val ()).To (Equal (int64 (2 )))
2620
+ Expect (hSet .Val ()).To (Equal (int64 (3 )))
2620
2621
2621
2622
hGetAll = client .HGetAll (ctx , "hash4" )
2622
2623
Expect (hGetAll .Err ()).NotTo (HaveOccurred ())
2623
2624
Expect (hGetAll .Val ()).To (Equal (map [string ]string {
2624
2625
"set1" : "val" ,
2625
- "set6" : fmt .Sprintf ("{\" Date\" :\" %s\" }" , now .Format (time .RFC3339Nano )),
2626
+ "set5" : now .Format (time .RFC3339Nano ),
2627
+ "set6" : `{"Number":5}` ,
2626
2628
}))
2627
2629
})
2628
2630
@@ -7665,12 +7667,16 @@ type numberStruct struct {
7665
7667
Number int
7666
7668
}
7667
7669
7668
- func (s * numberStruct ) MarshalBinary () ([]byte , error ) {
7669
- return json .Marshal (s )
7670
+ func (n * numberStruct ) MarshalBinary () ([]byte , error ) {
7671
+ return json .Marshal (n )
7670
7672
}
7671
7673
7672
- func (s * numberStruct ) UnmarshalBinary (b []byte ) error {
7673
- return json .Unmarshal (b , s )
7674
+ func (n * numberStruct ) UnmarshalBinary (b []byte ) error {
7675
+ return json .Unmarshal (b , n )
7676
+ }
7677
+
7678
+ func (n * numberStruct ) ScanRedis (str string ) error {
7679
+ return json .Unmarshal ([]byte (str ), n )
7674
7680
}
7675
7681
7676
7682
func deref (viface interface {}) interface {} {
@@ -7680,15 +7686,3 @@ func deref(viface interface{}) interface{} {
7680
7686
}
7681
7687
return v .Interface ()
7682
7688
}
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