redisCluster.go 974 Bytes
Newer Older
hujiebin's avatar
hujiebin committed
1 2 3 4 5 6 7 8 9 10 11
package redisCli

import (
	"context"
	"git.hilo.cn/hilo-common/mylogrus"
	"git.hilo.cn/hilo-common/resource/config"
	"github.com/go-redis/redis/v8"
)

var RedisClusterClient *redis.Client

hujiebin's avatar
hujiebin committed
12
func InitCluster() {
hujiebin's avatar
hujiebin committed
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
	RedisClusterClient = redis.NewClient(&redis.Options{
		Addr:         config.GetConfigRedis().REDIS_CLUSTER_HOST,
		Password:     config.GetConfigRedis().REDIS_CLUSTER_PASSWORD, // no password set
		DB:           0,                                              // use default DB
		PoolSize:     20,
		MinIdleConns: 20,
	})
	mylogrus.MyLog.Infoln(config.GetConfigRedis().REDIS_HOST)
	mylogrus.MyLog.Infoln(config.GetConfigRedis().REDIS_PASSWORD)
	pong, err := RedisClient.Ping(context.Background()).Result()
	if err != nil {
		mylogrus.MyLog.Warn(err)
		mylogrus.MyLog.Fatal("redis cluster db0 connect fail")
	} else {
		mylogrus.MyLog.Info("redis cluster db0 connection success - ", pong)
	}
}

func GetClusterRedis() *redis.Client {
	return RedisClusterClient
}