package main
import (
"fmt"
"github.com/gogf/gf/v2/container/gvar"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gctx"
)
func main() {
type User struct {
Id int
Name string
}
var (
ctx = gctx.New()
err error
result *gvar.Var
key = "user"
user = g.Map{
"id": 10000,
"name": "john",
}
)
_, err = g.Redis().Do(ctx, "SET", key, user)
if err != nil {
panic(err)
}
result, err = g.Redis().Do(ctx, "GET", key)
if err != nil {
panic(err)
}
var user2 *User
if err = result.Struct(&user2); err != nil {
panic(err)
}
fmt.Println(user2.Id, user2.Name)
}