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)
}
1 Comment
1254624823
key := "zset_test"
data := []string{"test4", "test3"}
dataStr := strings.Join(data, " ")
i, err := g.Redis().ZRem(context.Background(), key, dataStr)
fmt.Println(i, err)
上面这段代码并不能删除了0条,而zset_test中确实有test4, test3这两个元素。
还尝试过:
i, err := g.Redis().Do(context.Background(), "ZREM", key, g.Slice{"test4", "test3"})
i, err := g.Redis().Do(context.Background(), "ZREM", key, data)
i, err := g.Redis().ZRem(context.Background(), key, data)
i, err := g.Redis().ZRem(context.Background(), key, nil, data)