go-redis icon indicating copy to clipboard operation
go-redis copied to clipboard

`HMGet` can't scan type `time.Time`

Open ryan961 opened this issue 3 years ago • 0 comments

Version: github.com/go-redis/redis/v8 v8.11.4

Hi, I found the test case(https://github.com/go-redis/redis/blob/e061db8c13fd6b5e007d73370873026e360719de/redis_test.go#L274),time.Time can be scanned to object. But it's wrong when I used it in hmget(...).scan(&u) image

type User struct {
	Name string `json:"name" redis:"name"`
	Age  int64  `json:"age" redis:"age"`
	CreateAt time.Time `json:"createAt" redis:"createAt"`
}

func main() {
                ......


		fmt.Println(cli.HMSet(ctx, "joe", map[string]interface{}{
			"name":     "joe",
			"age":      10,
			"createAt": time.Now(),
		}).Result())

		u := User{}
		fmt.Println(cli.HMGet(ctx, "joe", "name", "age", "city", "createAt").Scan(&u))
		fmt.Println(u)
                
                ......
}

image

ryan961 avatar Jul 19 '22 02:07 ryan961