package main
import (
"fmt"
_ "github.com/gogf/gf/contrib/nosql/redis/v2"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gctx"
)
func main() {
var (
ctx = gctx.New()
key = "key"
)
_, err := g.Redis().HSet(ctx, key, g.Map{
"id": 1,
"name": "john",
"score": 100,
})
if err != nil {
g.Log().Fatal(ctx, err)
}
// retrieve hash map
value, err := g.Redis().HGetAll(ctx, key)
if err != nil {
g.Log().Fatal(ctx, err)
}
fmt.Println(value.Map())
// scan to struct
type User struct {
Id uint64
Name string
Score float64
}
var user *User
if err = value.Scan(&user); err != nil {
g.Log().Fatal(ctx, err)
}
g.Dump(user)
}
2 Comments
小肥坨
不支持SET integer类型数据吗
wansq
请问如下redis命令使用g.Redis()如何执行呢
sadd m 1 2 3 4 5 6 7