This commit is contained in:
lizhuang
2023-04-04 17:56:44 +08:00
parent 6a3fa25b7d
commit 46025f6011
93 changed files with 8110 additions and 0 deletions

37
server/plugin/db/redis.go Normal file
View File

@@ -0,0 +1,37 @@
package db
import (
"context"
"github.com/redis/go-redis/v9"
"server/config"
"time"
)
/*
redis 工具类
*/
var Rdb *redis.Client
var Cxt = context.Background()
// InitRedisConn 初始化redis客户端
func InitRedisConn() error {
Rdb = redis.NewClient(&redis.Options{
Addr: config.RedisAddr,
Password: config.RedisPassword,
DB: config.RedisDBNo,
PoolSize: 10, // 默认连接数
DialTimeout: time.Second * 10, // 超时时间
})
// 测试连接是否正常
_, err := Rdb.Ping(Cxt).Result()
if err != nil {
panic(err)
}
return nil
}
// 关闭redis连接
func CloseRedis() error {
return Rdb.Close()
}