mirror of
https://github.com/ProudMuBai/GoFilm.git
synced 2026-03-02 09:24:41 +08:00
init
This commit is contained in:
37
server/plugin/db/redis.go
Normal file
37
server/plugin/db/redis.go
Normal 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()
|
||||
}
|
||||
Reference in New Issue
Block a user