Du kan inte välja fler än 25 ämnen
Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
50 rader
1.1 KiB
50 rader
1.1 KiB
3 år sedan
|
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()
|
||
|
}
|