Commit 6320e420 authored by hujiebin's avatar hujiebin

feat:添加redis-cluster

parent 72fcf402
......@@ -10,4 +10,5 @@ type CtxAndDb struct {
Db *gorm.DB
*mycontext.MyContext
Redis *redis.Client
RedisCluster *redis.Client
}
......@@ -24,6 +24,7 @@ func CreateModelContext(myContext *mycontext.MyContext) *Model {
Db: mysql.Db,
MyContext: myContext,
Redis: redisCli.GetRedis(),
RedisCluster: redisCli.GetClusterRedis(),
},
}
}
......@@ -34,6 +35,7 @@ func CreateModelNil() *Model {
Db: mysql.Db,
MyContext: mycontext.CreateMyContext(nil),
Redis: redisCli.GetRedis(),
RedisCluster: redisCli.GetClusterRedis(),
},
}
}
......
......@@ -26,12 +26,14 @@ func CreateService(myContext *mycontext.MyContext) *Service {
Db: mysql.Db,
MyContext: mycontext.CreateMyContext(nil),
Redis: redisCli.GetRedis(),
RedisCluster: redisCli.GetClusterRedis(),
}}
} else {
return &Service{CtxAndDb: &CtxAndDb{
Db: mysql.Db,
MyContext: myContext,
Redis: redisCli.GetRedis(),
RedisCluster: redisCli.GetClusterRedis(),
}}
}
}
......
......@@ -28,6 +28,8 @@ type MysqlCodeConfig struct {
type RedisConfig struct {
REDIS_HOST string
REDIS_PASSWORD string
REDIS_CLUSTER_HOST string
REDIS_CLUSTER_PASSWORD string
}
//jwt
......
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
func Init() {
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
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment