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