mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
redis interface
This commit is contained in:
parent
89ac29a019
commit
b3dcff2d76
@ -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,22 +119,29 @@ func init() {
|
||||
// )
|
||||
// },
|
||||
//}
|
||||
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())
|
||||
if config.Config.Redis.EnableCluster {
|
||||
DB.rdb = go_redis.NewClusterClient(&go_redis.ClusterOptions{
|
||||
Addrs: []string{config.Config.Redis.DBAddress},
|
||||
PoolSize: 50,
|
||||
Password: config.Config.Redis.DBPassWord,
|
||||
})
|
||||
_, 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, // 连接池大小
|
||||
})
|
||||
_, err = DB.rdb.Ping(ctx).Result()
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user