@@ -2585,7 +2585,7 @@ var _ = Describe("Commands", func() {
25852585 Set3 time.Duration `redis:"set3,omitempty"`
25862586 Set4 string `redis:"set4,omitempty"`
25872587 Set5 time.Time `redis:"set5,omitempty"`
2588- Set6 childStruct `redis:"set6,omitempty"`
2588+ Set6 * numberStruct `redis:"set6,omitempty"`
25892589 }
25902590
25912591 hSet = client .HSet (ctx , "hash3" , & setOmitEmpty {
@@ -2606,23 +2606,25 @@ var _ = Describe("Commands", func() {
26062606 Expect (hash3 .Set3 ).To (Equal (time .Duration (0 )))
26072607 Expect (hash3 .Set4 ).To (Equal ("" ))
26082608 Expect (hash3 .Set5 ).To (Equal (time.Time {}))
2609- Expect (hash3 .Set6 ).To (Equal ( childStruct {} ))
2609+ Expect (hash3 .Set6 ).To (BeNil ( ))
26102610
26112611 now := time .Now ()
26122612 hSet = client .HSet (ctx , "hash4" , setOmitEmpty {
26132613 Set1 : "val" ,
2614- Set6 : childStruct {
2615- Date : now ,
2614+ Set5 : now ,
2615+ Set6 : & numberStruct {
2616+ Number : 5 ,
26162617 },
26172618 })
26182619 Expect (hSet .Err ()).NotTo (HaveOccurred ())
2619- Expect (hSet .Val ()).To (Equal (int64 (2 )))
2620+ Expect (hSet .Val ()).To (Equal (int64 (3 )))
26202621
26212622 hGetAll = client .HGetAll (ctx , "hash4" )
26222623 Expect (hGetAll .Err ()).NotTo (HaveOccurred ())
26232624 Expect (hGetAll .Val ()).To (Equal (map [string ]string {
26242625 "set1" : "val" ,
2625- "set6" : fmt .Sprintf ("{\" Date\" :\" %s\" }" , now .Format (time .RFC3339Nano )),
2626+ "set5" : now .Format (time .RFC3339Nano ),
2627+ "set6" : `{"Number":5}` ,
26262628 }))
26272629 })
26282630
@@ -7665,12 +7667,16 @@ type numberStruct struct {
76657667 Number int
76667668}
76677669
7668- func (s * numberStruct ) MarshalBinary () ([]byte , error ) {
7669- return json .Marshal (s )
7670+ func (n * numberStruct ) MarshalBinary () ([]byte , error ) {
7671+ return json .Marshal (n )
76707672}
76717673
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 )
76747680}
76757681
76767682func deref (viface interface {}) interface {} {
@@ -7680,15 +7686,3 @@ func deref(viface interface{}) interface{} {
76807686 }
76817687 return v .Interface ()
76827688}
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