package main
import (
"fmt"
_ "github.com/gogf/gf/contrib/nosql/redis/v2"
"github.com/gogf/gf/v2/database/gredis"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gctx"
)
var (
config = gredis.Config{
Address: "127.0.0.1:6379",
Db: 1,
Pass: "password",
}
group = "cache"
ctx = gctx.New()
)
func main() {
gredis.SetConfig(&config, group)
_, err := g.Redis(group).Set(ctx, "key", "value")
if err != nil {
g.Log().Fatal(ctx, err)
}
value, err := g.Redis(group).Get(ctx, "key")
if err != nil {
g.Log().Fatal(ctx, err)
}
fmt.Println(value.String())
}
5 Comments
unite小伟
key的过期时间是在哪里设置?
aries
gleke
D.Rose
你好,我将 redis 闲置的最小连接数设置为 4,为什么这四个闲置连接,永远不会被用到呢?
fd=9 name= age=14 idle=14 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=NULL
fd=11 name= age=14 idle=14 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=NULL
fd=14 name= age=14 idle=14 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=NULL
fd=12 name= age=14 idle=14 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=NULL
fd=10 name= age=14 idle=3 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=get
我执行的命令,都会再重新创建啊一个连接,那 4 个闲置连接,好像用于都不会被使用,是我的配置有问题吗?
edzhao
redis 能否有像mysql 那种debug模式,以及日志