Merge remote-tracking branch 'origin/superGroup' into superGroup

pull/236/head
skiffer-git 2 years ago
commit ceaa0b61eb

@ -39,6 +39,7 @@ redis:
dbMaxActive: 0
dbIdleTimeout: 120
dbPassWord: openIM #redis密码 建议修改
enableCluster: false
kafka:
ws2mschat:

@ -102,6 +102,7 @@ type config struct {
DBMaxActive int `yaml:"dbMaxActive"`
DBIdleTimeout int `yaml:"dbIdleTimeout"`
DBPassWord string `yaml:"dbPassWord"`
EnableCluster bool `yaml:"enableCluster"`
}
RpcPort struct {
OpenImUserPort []int `yaml:"openImUserPort"`

@ -28,7 +28,14 @@ type DataBases struct {
mgoSession *mgo.Session
//redisPool *redis.Pool
mongoClient *mongo.Client
rdb *go_redis.Client
rdb go_redis.UniversalClient
}
type RedisClient struct {
client *go_redis.Client
cluster *go_redis.ClusterClient
go_redis.UniversalClient
enableCluster bool
}
func key(dbAddress, dbName string) string {
@ -112,23 +119,29 @@ func init() {
// )
// },
//}
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
if config.Config.Redis.EnableCluster {
DB.rdb = go_redis.NewClusterClient(&go_redis.ClusterOptions{
Addrs: []string{config.Config.Redis.DBAddress},
PoolSize: 50,
})
_, err = DB.rdb.Ping(ctx).Result()
if err != nil {
panic(err.Error())
}
} else {
DB.rdb = go_redis.NewClient(&go_redis.Options{
Addr: config.Config.Redis.DBAddress,
Password: config.Config.Redis.DBPassWord, // no password set
DB: 0, // use default DB
PoolSize: 100, // 连接池大小
})
//DB.rdb = go_redis.NewClusterClient(&go_redis.ClusterOptions{
// Addrs: []string{config.Config.Redis.DBAddress},
// PoolSize: 50,
//Password: config.Config.Redis.DBPassWord,
//})
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
_, err = DB.rdb.Ping(ctx).Result()
if err != nil {
panic(err.Error())
}
}
}
func createMongoIndex(client *mongo.Client, collection string, isUnique bool, keys ...string) error {

Loading…
Cancel
Save