mirror of
https://github.com/astaxie/beego.git
synced 2024-11-21 22:40:54 +00:00
Add new config option into provider struct
This commit is contained in:
parent
d1d9df74c7
commit
7267f5e573
@ -114,6 +114,9 @@ type Provider struct {
|
||||
poolsize int
|
||||
password string
|
||||
dbNum int
|
||||
idleTimeout time.Duration
|
||||
idleCheckFrequency time.Duration
|
||||
maxRetries int
|
||||
poollist *redis.Client
|
||||
}
|
||||
|
||||
@ -149,25 +152,22 @@ func (rp *Provider) SessionInit(maxlifetime int64, savePath string) error {
|
||||
} else {
|
||||
rp.dbNum = 0
|
||||
}
|
||||
var idleTimeout time.Duration = 0
|
||||
if len(configs) > 4 {
|
||||
timeout, err := strconv.Atoi(configs[4])
|
||||
if err == nil && timeout > 0 {
|
||||
idleTimeout = time.Duration(timeout) * time.Second
|
||||
rp.idleTimeout = time.Duration(timeout) * time.Second
|
||||
}
|
||||
}
|
||||
var idleCheckFrequency time.Duration = 0
|
||||
if len(configs) > 5 {
|
||||
checkFrequency, err := strconv.Atoi(configs[5])
|
||||
if err == nil && checkFrequency > 0 {
|
||||
idleCheckFrequency = time.Duration(checkFrequency) * time.Second
|
||||
rp.idleCheckFrequency = time.Duration(checkFrequency) * time.Second
|
||||
}
|
||||
}
|
||||
var maxRetries = 0
|
||||
if len(configs) > 6 {
|
||||
retries, err := strconv.Atoi(configs[6])
|
||||
if err == nil && retries > 0 {
|
||||
maxRetries = retries
|
||||
rp.maxRetries = retries
|
||||
}
|
||||
}
|
||||
|
||||
@ -176,9 +176,9 @@ func (rp *Provider) SessionInit(maxlifetime int64, savePath string) error {
|
||||
Password: rp.password,
|
||||
PoolSize: rp.poolsize,
|
||||
DB: rp.dbNum,
|
||||
IdleTimeout: idleTimeout,
|
||||
IdleCheckFrequency: idleCheckFrequency,
|
||||
MaxRetries: maxRetries,
|
||||
IdleTimeout: rp.idleTimeout,
|
||||
IdleCheckFrequency: rp.idleCheckFrequency,
|
||||
MaxRetries: rp.maxRetries,
|
||||
})
|
||||
|
||||
return rp.poollist.Ping().Err()
|
||||
@ -249,4 +249,3 @@ func (rp *Provider) SessionAll() int {
|
||||
func init() {
|
||||
session.Register("redis", redispder)
|
||||
}
|
||||
|
||||
|
@ -112,6 +112,9 @@ type Provider struct {
|
||||
poolsize int
|
||||
password string
|
||||
dbNum int
|
||||
idleTimeout time.Duration
|
||||
idleCheckFrequency time.Duration
|
||||
maxRetries int
|
||||
poollist *rediss.ClusterClient
|
||||
}
|
||||
|
||||
@ -147,25 +150,22 @@ func (rp *Provider) SessionInit(maxlifetime int64, savePath string) error {
|
||||
} else {
|
||||
rp.dbNum = 0
|
||||
}
|
||||
var idleTimeout time.Duration = 0
|
||||
if len(configs) > 4 {
|
||||
timeout, err := strconv.Atoi(configs[4])
|
||||
if err == nil && timeout > 0 {
|
||||
idleTimeout = time.Duration(timeout) * time.Second
|
||||
rp.idleTimeout = time.Duration(timeout) * time.Second
|
||||
}
|
||||
}
|
||||
var idleCheckFrequency time.Duration = 0
|
||||
if len(configs) > 5 {
|
||||
checkFrequency, err := strconv.Atoi(configs[5])
|
||||
if err == nil && checkFrequency > 0 {
|
||||
idleCheckFrequency = time.Duration(checkFrequency) * time.Second
|
||||
rp.idleCheckFrequency = time.Duration(checkFrequency) * time.Second
|
||||
}
|
||||
}
|
||||
var maxRetries = 0
|
||||
if len(configs) > 6 {
|
||||
retries, err := strconv.Atoi(configs[6])
|
||||
if err == nil && retries > 0 {
|
||||
maxRetries = retries
|
||||
rp.maxRetries = retries
|
||||
}
|
||||
}
|
||||
|
||||
@ -173,9 +173,9 @@ func (rp *Provider) SessionInit(maxlifetime int64, savePath string) error {
|
||||
Addrs: strings.Split(rp.savePath, ";"),
|
||||
Password: rp.password,
|
||||
PoolSize: rp.poolsize,
|
||||
IdleTimeout: idleTimeout,
|
||||
IdleCheckFrequency: idleCheckFrequency,
|
||||
MaxRetries: maxRetries,
|
||||
IdleTimeout: rp.idleTimeout,
|
||||
IdleCheckFrequency: rp.idleCheckFrequency,
|
||||
MaxRetries: rp.maxRetries,
|
||||
})
|
||||
return rp.poollist.Ping().Err()
|
||||
}
|
||||
|
@ -112,6 +112,9 @@ type Provider struct {
|
||||
poolsize int
|
||||
password string
|
||||
dbNum int
|
||||
idleTimeout time.Duration
|
||||
idleCheckFrequency time.Duration
|
||||
maxRetries int
|
||||
poollist *redis.Client
|
||||
masterName string
|
||||
}
|
||||
@ -157,25 +160,22 @@ func (rp *Provider) SessionInit(maxlifetime int64, savePath string) error {
|
||||
} else {
|
||||
rp.masterName = "mymaster"
|
||||
}
|
||||
var idleTimeout time.Duration = 0
|
||||
if len(configs) > 5 {
|
||||
timeout, err := strconv.Atoi(configs[4])
|
||||
if err == nil && timeout > 0 {
|
||||
idleTimeout = time.Duration(timeout) * time.Second
|
||||
rp.idleTimeout = time.Duration(timeout) * time.Second
|
||||
}
|
||||
}
|
||||
var idleCheckFrequency time.Duration = 0
|
||||
if len(configs) > 6 {
|
||||
checkFrequency, err := strconv.Atoi(configs[5])
|
||||
if err == nil && checkFrequency > 0 {
|
||||
idleCheckFrequency = time.Duration(checkFrequency) * time.Second
|
||||
rp.idleCheckFrequency = time.Duration(checkFrequency) * time.Second
|
||||
}
|
||||
}
|
||||
var maxRetries = 0
|
||||
if len(configs) > 7 {
|
||||
retries, err := strconv.Atoi(configs[6])
|
||||
if err == nil && retries > 0 {
|
||||
maxRetries = retries
|
||||
rp.maxRetries = retries
|
||||
}
|
||||
}
|
||||
|
||||
@ -185,9 +185,9 @@ func (rp *Provider) SessionInit(maxlifetime int64, savePath string) error {
|
||||
PoolSize: rp.poolsize,
|
||||
DB: rp.dbNum,
|
||||
MasterName: rp.masterName,
|
||||
IdleTimeout: idleTimeout,
|
||||
IdleCheckFrequency: idleCheckFrequency,
|
||||
MaxRetries: maxRetries,
|
||||
IdleTimeout: rp.idleTimeout,
|
||||
IdleCheckFrequency: rp.idleCheckFrequency,
|
||||
MaxRetries: rp.maxRetries,
|
||||
})
|
||||
|
||||
return rp.poollist.Ping().Err()
|
||||
|
Loading…
Reference in New Issue
Block a user