优化redis客户端连接池大小配置
This commit is contained in:
parent
001c93b3a0
commit
bbb9958687
@ -8,7 +8,7 @@ import (
|
||||
"github.com/go-redis/redis/v8"
|
||||
)
|
||||
|
||||
func NewSys(RedisUrl []string, RedisPassword string, timeOut time.Duration,
|
||||
func NewSys(RedisUrl []string, RedisPassword string, poolSize int, timeOut time.Duration,
|
||||
codec core.ICodec,
|
||||
) (sys *Redis, err error) {
|
||||
var (
|
||||
@ -17,6 +17,7 @@ func NewSys(RedisUrl []string, RedisPassword string, timeOut time.Duration,
|
||||
client = redis.NewClusterClient(&redis.ClusterOptions{
|
||||
Addrs: RedisUrl,
|
||||
Password: RedisPassword,
|
||||
PoolSize: poolSize,
|
||||
DialTimeout: timeOut,
|
||||
ReadTimeout: timeOut,
|
||||
WriteTimeout: timeOut,
|
||||
|
@ -22,6 +22,7 @@ type Options struct {
|
||||
Redis_Single_DB int
|
||||
Redis_Cluster_Addr []string
|
||||
Redis_Cluster_Password string
|
||||
PoolSize int
|
||||
TimeOut time.Duration
|
||||
Codec core.ICodec
|
||||
}
|
||||
@ -81,6 +82,7 @@ func newOptions(config map[string]interface{}, opts ...Option) Options {
|
||||
Redis_Single_DB: 1,
|
||||
Redis_Cluster_Addr: []string{"127.0.0.1:6379"},
|
||||
Redis_Cluster_Password: "",
|
||||
PoolSize: 200,
|
||||
TimeOut: time.Second * 3,
|
||||
}
|
||||
if config != nil {
|
||||
@ -99,6 +101,7 @@ func newOptionsByOption(opts ...Option) Options {
|
||||
Redis_Single_DB: 1,
|
||||
Redis_Cluster_Addr: []string{"127.0.0.1:6379"},
|
||||
Redis_Cluster_Password: "",
|
||||
PoolSize: 200,
|
||||
TimeOut: time.Second * 3,
|
||||
}
|
||||
for _, o := range opts {
|
||||
|
@ -30,6 +30,7 @@ func (this *Redis) init() (err error) {
|
||||
this.options.Redis_Single_Addr,
|
||||
this.options.Redis_Single_Password,
|
||||
this.options.Redis_Single_DB,
|
||||
this.options.PoolSize,
|
||||
this.options.TimeOut,
|
||||
this,
|
||||
)
|
||||
@ -37,6 +38,7 @@ func (this *Redis) init() (err error) {
|
||||
this.client, err = cluster.NewSys(
|
||||
this.options.Redis_Cluster_Addr,
|
||||
this.options.Redis_Cluster_Password,
|
||||
this.options.PoolSize,
|
||||
this.options.TimeOut,
|
||||
this,
|
||||
)
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
"github.com/go-redis/redis/v8"
|
||||
)
|
||||
|
||||
func NewSys(RedisUrl, RedisPassword string, RedisDB int, timeOut time.Duration,
|
||||
func NewSys(RedisUrl, RedisPassword string, RedisDB int, poolSize int, timeOut time.Duration,
|
||||
codec core.ICodec,
|
||||
) (sys *Redis, err error) {
|
||||
var (
|
||||
@ -18,6 +18,7 @@ func NewSys(RedisUrl, RedisPassword string, RedisDB int, timeOut time.Duration,
|
||||
Addr: RedisUrl,
|
||||
Password: RedisPassword,
|
||||
DB: RedisDB,
|
||||
PoolSize: poolSize,
|
||||
DialTimeout: timeOut,
|
||||
WriteTimeout: timeOut,
|
||||
ReadTimeout: timeOut,
|
||||
|
@ -373,6 +373,7 @@ func convertServiceSttings(config *comm.GameConfig, id int, stype string, ip str
|
||||
"RedisAddr": config.LoaclDB.RedisAddr,
|
||||
"RedisPassword": config.LoaclDB.RedisPassword,
|
||||
"RedisDB": config.LoaclDB.RedisDB,
|
||||
"PoolSize": 300,
|
||||
"MongodbUrl": config.LoaclDB.MongodbUrl,
|
||||
"MongodbDatabase": config.LoaclDB.MongodbDatabase,
|
||||
"CrossConfig": crosspath,
|
||||
|
Loading…
Reference in New Issue
Block a user