Golang redigo hmset hset 问题

jackluo · · 8306 次点击
c, err := dial() if err != nil { panic(err) } defer c.Close() var p1, p2 struct { Title string `redis:"title"` Author string `redis:"author"` Body string `redis:"body"` } p1.Title = "Example" p1.Author = "Gary" p1.Body = "Hello" if _, err := c.Do("HMSET", redis.Args{}.Add("id1").AddFlat(&p1)...); err != nil { panic(err) } m := map[string]string{ "title": "Example2", "author": "Steve", "body": "Map", } if _, err := c.Do("HMSET", redis.Args{}.Add("id2").AddFlat(m)...); err != nil { panic(err) } for _, id := range []string{"id1", "id2"} { v, err := redis.Values(c.Do("HGETALL", id)) if err != nil { panic(err) } if err := redis.ScanStruct(v, &p2); err != nil { panic(err) } fmt.Printf("%+v\n", p2) }
#1