mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-25 02:58:26 +08:00
redis interface
This commit is contained in:
parent
89ac29a019
commit
b3dcff2d76
@ -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,31 @@ 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,
|
||||||
|
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{
|
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…
x
Reference in New Issue
Block a user