码农笔录博客源码
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

49 lines
1.1 KiB

package utils
import (
"fmt"
"github.com/beego/beego/v2/server/web"
"github.com/go-redis/redis"
)
const (
REDIS_NETWORK = "tcp"
REDIS_DB = 7
)
type RedisClient struct {
}
func (r RedisClient) GetClient() *redis.Client {
REDIS_HOST, _ := web.AppConfig.String("redisHost")
REDIS_PORT, _ := web.AppConfig.String("redisPort")
REDIS_PASSWORD, _ := web.AppConfig.String("redisPwd")
options := redis.Options{
Network: REDIS_NETWORK,
Addr: fmt.Sprintf("%s:%s", REDIS_HOST, REDIS_PORT),
Dialer: nil,
OnConnect: nil,
Password: REDIS_PASSWORD,
DB: REDIS_DB,
MaxRetries: 0,
MinRetryBackoff: 0,
MaxRetryBackoff: 0,
DialTimeout: 0,
ReadTimeout: 0,
WriteTimeout: 0,
PoolSize: 0,
MinIdleConns: 0,
MaxConnAge: 0,
PoolTimeout: 0,
IdleTimeout: 0,
IdleCheckFrequency: 0,
TLSConfig: nil,
}
// 新建一个client
clientRedis := redis.NewClient(&options)
return clientRedis
}
func (r RedisClient) CloseClient(client *redis.Client) {
defer client.Close()
}