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 dbMaxActive: 0
dbIdleTimeout: 120 dbIdleTimeout: 120
dbPassWord: openIM #redis密码 建议修改 dbPassWord: openIM #redis密码 建议修改
enableCluster: false
kafka: kafka:
ws2mschat: ws2mschat:

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

@ -28,7 +28,14 @@ type DataBases struct {
mgoSession *mgo.Session mgoSession *mgo.Session
//redisPool *redis.Pool //redisPool *redis.Pool
mongoClient *mongo.Client 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 { func key(dbAddress, dbName string) string {
@ -112,24 +119,30 @@ 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{ DB.rdb = go_redis.NewClient(&go_redis.Options{
Addr: config.Config.Redis.DBAddress, Addr: config.Config.Redis.DBAddress,
Password: config.Config.Redis.DBPassWord, // no password set Password: config.Config.Redis.DBPassWord, // no password set
DB: 0, // use default DB DB: 0, // use default DB
PoolSize: 100, // 连接池大小 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() _, err = DB.rdb.Ping(ctx).Result()
if err != nil { if err != nil {
panic(err.Error()) panic(err.Error())
} }
} }
}
func createMongoIndex(client *mongo.Client, collection string, isUnique bool, keys ...string) error { func createMongoIndex(client *mongo.Client, collection string, isUnique bool, keys ...string) error {
db := client.Database(config.Config.Mongo.DBDatabase).Collection(collection) db := client.Database(config.Config.Mongo.DBDatabase).Collection(collection)

Loading…
Cancel
Save