@@ -14,6 +14,15 @@ import (
1414 "github.com/go-redis/redis/v9/internal/proto"
1515)
1616
17+ type TimeValue struct {
18+ time.Time
19+ }
20+
21+ func (t * TimeValue ) ScanRedis (s string ) (err error ) {
22+ t .Time , err = time .Parse (time .RFC3339Nano , s )
23+ return
24+ }
25+
1726var _ = Describe ("Commands" , func () {
1827 ctx := context .TODO ()
1928 var client * redis.Client
@@ -1192,19 +1201,28 @@ var _ = Describe("Commands", func() {
11921201 })
11931202
11941203 It ("should scan Mget" , func () {
1195- err := client .MSet (ctx , "key1" , "hello1" , "key2" , 123 ).Err ()
1204+ now := time .Now ()
1205+
1206+ err := client .MSet (ctx , "key1" , "hello1" , "key2" , 123 , "time" , now .Format (time .RFC3339Nano )).Err ()
11961207 Expect (err ).NotTo (HaveOccurred ())
11971208
1198- res := client .MGet (ctx , "key1" , "key2" , "_" )
1209+ res := client .MGet (ctx , "key1" , "key2" , "_" , "time" )
11991210 Expect (res .Err ()).NotTo (HaveOccurred ())
12001211
12011212 type data struct {
1202- Key1 string `redis:"key1"`
1203- Key2 int `redis:"key2"`
1213+ Key1 string `redis:"key1"`
1214+ Key2 int `redis:"key2"`
1215+ Time TimeValue `redis:"time"`
12041216 }
12051217 var d data
12061218 Expect (res .Scan (& d )).NotTo (HaveOccurred ())
1207- Expect (d ).To (Equal (data {Key1 : "hello1" , Key2 : 123 }))
1219+ Expect (d .Time .UnixNano ()).To (Equal (now .UnixNano ()))
1220+ d .Time .Time = time.Time {}
1221+ Expect (d ).To (Equal (data {
1222+ Key1 : "hello1" ,
1223+ Key2 : 123 ,
1224+ Time : TimeValue {Time : time.Time {}},
1225+ }))
12081226 })
12091227
12101228 It ("should MSetNX" , func () {
@@ -1732,19 +1750,28 @@ var _ = Describe("Commands", func() {
17321750 })
17331751
17341752 It ("should scan" , func () {
1735- err := client .HMSet (ctx , "hash" , "key1" , "hello1" , "key2" , 123 ).Err ()
1753+ now := time .Now ()
1754+
1755+ err := client .HMSet (ctx , "hash" , "key1" , "hello1" , "key2" , 123 , "time" , now .Format (time .RFC3339Nano )).Err ()
17361756 Expect (err ).NotTo (HaveOccurred ())
17371757
17381758 res := client .HGetAll (ctx , "hash" )
17391759 Expect (res .Err ()).NotTo (HaveOccurred ())
17401760
17411761 type data struct {
1742- Key1 string `redis:"key1"`
1743- Key2 int `redis:"key2"`
1762+ Key1 string `redis:"key1"`
1763+ Key2 int `redis:"key2"`
1764+ Time TimeValue `redis:"time"`
17441765 }
17451766 var d data
17461767 Expect (res .Scan (& d )).NotTo (HaveOccurred ())
1747- Expect (d ).To (Equal (data {Key1 : "hello1" , Key2 : 123 }))
1768+ Expect (d .Time .UnixNano ()).To (Equal (now .UnixNano ()))
1769+ d .Time .Time = time.Time {}
1770+ Expect (d ).To (Equal (data {
1771+ Key1 : "hello1" ,
1772+ Key2 : 123 ,
1773+ Time : TimeValue {Time : time.Time {}},
1774+ }))
17481775 })
17491776
17501777 It ("should HIncrBy" , func () {
0 commit comments