Skip to content

Commit

Permalink
Merge pull request #405 from magederek/feat/redispool-poolsize-minidle
Browse files Browse the repository at this point in the history
feat: add redis options of minIdleConns and poolSize
  • Loading branch information
andrewshan authored Jun 6, 2022
2 parents 4de6409 + ce29e69 commit c02030d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
17 changes: 11 additions & 6 deletions common/redispool/redis_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ type Config struct {
KvAddr string `json:"kvAddr"`
KvUser string `json:"kvUser"`
KvPasswd string `json:"kvPasswd"`
MaxIdle int `json:"maxIdle"`
PoolSize int `json:"poolSize"`
MinIdleConns int `json:"minIdleConns"`
IdleTimeout commontime.Duration `json:"idleTimeout"`
ConnectTimeout commontime.Duration `json:"connectTimeout"`
MsgTimeout commontime.Duration `json:"msgTimeout"`
Expand All @@ -112,7 +113,8 @@ type Config struct {
// DefaultConfig redis pool configuration with default values
func DefaultConfig() *Config {
return &Config{
MaxIdle: 200,
PoolSize: 200,
MinIdleConns: 30,
IdleTimeout: commontime.Duration(120 * time.Second),
ConnectTimeout: commontime.Duration(300 * time.Millisecond),
MsgTimeout: commontime.Duration(300 * time.Millisecond),
Expand All @@ -132,8 +134,11 @@ func (c *Config) Validate() error {
if len(c.KvUser) > 0 && len(c.KvPasswd) == 0 { // password is required only when ACL's user is given
return errors.New("kvPasswd is empty")
}
if c.MaxIdle <= 0 {
return errors.New("maxIdle is empty")
if c.MinIdleConns <= 0 {
return errors.New("minIdleConns is empty")
}
if c.PoolSize <= 0 {
return errors.New("poolSize is empty")
}
if c.IdleTimeout == 0 {
return errors.New("idleTimeout is empty")
Expand Down Expand Up @@ -174,8 +179,8 @@ func NewPool(ctx context.Context, config *Config, statis plugin.Statis) *Pool {
DialTimeout: time.Duration(config.ConnectTimeout),
ReadTimeout: time.Duration(config.MsgTimeout),
WriteTimeout: time.Duration(config.MsgTimeout),
PoolSize: config.MaxIdle,
MinIdleConns: config.MaxIdle,
PoolSize: config.PoolSize,
MinIdleConns: config.MinIdleConns,
IdleTimeout: time.Duration(config.IdleTimeout),
}
if config.WithTLS {
Expand Down
3 changes: 2 additions & 1 deletion deploy/helm/templates/polaris-server-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ data:
{{- if .Values.polaris.storage.redis.password }}
kvPasswd: {{ .Values.polaris.storage.redis.password }}
{{- end }}
maxIdle: 200
poolSize: 200
minIdleConns: 30
idleTimeout: 120s
connectTimeout: 200ms
msgTimeout: 200ms
Expand Down
3 changes: 2 additions & 1 deletion deploy/standalone/k8s/02-polaris-server-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@ data:
# kvAddr: ##REDIS_ADDR##
# kvUser: ##REDIS_USER#
# kvPasswd: ##REDIS_PWD##
# maxIdle: 200
# poolSize: 200
# minIdleConns: 30
# idleTimeout: 120s
# connectTimeout: 200ms
# msgTimeout: 200ms
Expand Down
3 changes: 2 additions & 1 deletion polaris-server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ healthcheck:
# kvAddr: ##REDIS_ADDR##
# kvUser: ##REDIS_USER#
# kvPasswd: ##REDIS_PWD##
# maxIdle: 200
# poolSize: 200
# minIdleConns: 30
# idleTimeout: 120s
# connectTimeout: 200ms
# msgTimeout: 200ms
Expand Down
3 changes: 2 additions & 1 deletion test/discover/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ healthcheck:
# kvAddr: ##REDIS_ADDR##
# kvUser: ##REDIS_USER#
# kvPasswd: ##REDIS_PWD##
# maxIdle: 200
# poolSize: 200
# minIdleConns: 30
# idleTimeout: 120s
# connectTimeout: 200ms
# msgTimeout: 200ms
Expand Down

0 comments on commit c02030d

Please sign in to comment.