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

import (
	"context"
	"github.com/go-redis/redis/v8"
	"hilo-socketCenter/common/config"
	"hilo-socketCenter/common/mylogrus"
	"log"
)

JiebinHu's avatar
JiebinHu committed
11
var RedisCluster *redis.Client
hujiebin's avatar
hujiebin committed
12 13

func init() {
JiebinHu's avatar
JiebinHu committed
14 15 16 17
	RedisCluster = redis.NewClient(&redis.Options{
		Addr:         config.GetConfigRedis().REDIS_CLUSTER_HOST,
		Password:     config.GetConfigRedis().REDIS_CLUSTER_PASSWORD, // no password set
		DB:           0,                                              // use default DB
hujiebin's avatar
hujiebin committed
18 19 20
		PoolSize:     200,
		MinIdleConns: 20,
	})
JiebinHu's avatar
JiebinHu committed
21
	pong, err := RedisCluster.Ping(context.Background()).Result()
hujiebin's avatar
hujiebin committed
22 23
	if err != nil {
		mylogrus.MyLog.Warn(err)
JiebinHu's avatar
JiebinHu committed
24
		mylogrus.MyLog.Fatal("redis db0 connect fail")
hujiebin's avatar
hujiebin committed
25
	} else {
JiebinHu's avatar
JiebinHu committed
26
		log.Println("redis db0 connection success - " + pong)
hujiebin's avatar
hujiebin committed
27 28 29 30 31
	}
	// log hook
	//RedisClient.AddHook(redisHook{})
}

JiebinHu's avatar
JiebinHu committed
32 33
func GetRedisCluster() *redis.Client {
	return RedisCluster
hujiebin's avatar
hujiebin committed
34
}