mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 04:40:55 +00:00
Add new config option into provider struct
This commit is contained in:
parent
d1d9df74c7
commit
7267f5e573
@ -109,12 +109,15 @@ func (rs *SessionStore) SessionRelease(w http.ResponseWriter) {
|
|||||||
|
|
||||||
// Provider redis session provider
|
// Provider redis session provider
|
||||||
type Provider struct {
|
type Provider struct {
|
||||||
maxlifetime int64
|
maxlifetime int64
|
||||||
savePath string
|
savePath string
|
||||||
poolsize int
|
poolsize int
|
||||||
password string
|
password string
|
||||||
dbNum int
|
dbNum int
|
||||||
poollist *redis.Client
|
idleTimeout time.Duration
|
||||||
|
idleCheckFrequency time.Duration
|
||||||
|
maxRetries int
|
||||||
|
poollist *redis.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
// SessionInit init redis session
|
// SessionInit init redis session
|
||||||
@ -149,25 +152,22 @@ func (rp *Provider) SessionInit(maxlifetime int64, savePath string) error {
|
|||||||
} else {
|
} else {
|
||||||
rp.dbNum = 0
|
rp.dbNum = 0
|
||||||
}
|
}
|
||||||
var idleTimeout time.Duration = 0
|
|
||||||
if len(configs) > 4 {
|
if len(configs) > 4 {
|
||||||
timeout, err := strconv.Atoi(configs[4])
|
timeout, err := strconv.Atoi(configs[4])
|
||||||
if err == nil && timeout > 0 {
|
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 {
|
if len(configs) > 5 {
|
||||||
checkFrequency, err := strconv.Atoi(configs[5])
|
checkFrequency, err := strconv.Atoi(configs[5])
|
||||||
if err == nil && checkFrequency > 0 {
|
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 {
|
if len(configs) > 6 {
|
||||||
retries, err := strconv.Atoi(configs[6])
|
retries, err := strconv.Atoi(configs[6])
|
||||||
if err == nil && retries > 0 {
|
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,
|
Password: rp.password,
|
||||||
PoolSize: rp.poolsize,
|
PoolSize: rp.poolsize,
|
||||||
DB: rp.dbNum,
|
DB: rp.dbNum,
|
||||||
IdleTimeout: idleTimeout,
|
IdleTimeout: rp.idleTimeout,
|
||||||
IdleCheckFrequency: idleCheckFrequency,
|
IdleCheckFrequency: rp.idleCheckFrequency,
|
||||||
MaxRetries: maxRetries,
|
MaxRetries: rp.maxRetries,
|
||||||
})
|
})
|
||||||
|
|
||||||
return rp.poollist.Ping().Err()
|
return rp.poollist.Ping().Err()
|
||||||
@ -249,4 +249,3 @@ func (rp *Provider) SessionAll() int {
|
|||||||
func init() {
|
func init() {
|
||||||
session.Register("redis", redispder)
|
session.Register("redis", redispder)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,12 +107,15 @@ func (rs *SessionStore) SessionRelease(w http.ResponseWriter) {
|
|||||||
|
|
||||||
// Provider redis_cluster session provider
|
// Provider redis_cluster session provider
|
||||||
type Provider struct {
|
type Provider struct {
|
||||||
maxlifetime int64
|
maxlifetime int64
|
||||||
savePath string
|
savePath string
|
||||||
poolsize int
|
poolsize int
|
||||||
password string
|
password string
|
||||||
dbNum int
|
dbNum int
|
||||||
poollist *rediss.ClusterClient
|
idleTimeout time.Duration
|
||||||
|
idleCheckFrequency time.Duration
|
||||||
|
maxRetries int
|
||||||
|
poollist *rediss.ClusterClient
|
||||||
}
|
}
|
||||||
|
|
||||||
// SessionInit init redis_cluster session
|
// SessionInit init redis_cluster session
|
||||||
@ -147,35 +150,32 @@ func (rp *Provider) SessionInit(maxlifetime int64, savePath string) error {
|
|||||||
} else {
|
} else {
|
||||||
rp.dbNum = 0
|
rp.dbNum = 0
|
||||||
}
|
}
|
||||||
var idleTimeout time.Duration = 0
|
|
||||||
if len(configs) > 4 {
|
if len(configs) > 4 {
|
||||||
timeout, err := strconv.Atoi(configs[4])
|
timeout, err := strconv.Atoi(configs[4])
|
||||||
if err == nil && timeout > 0 {
|
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 {
|
if len(configs) > 5 {
|
||||||
checkFrequency, err := strconv.Atoi(configs[5])
|
checkFrequency, err := strconv.Atoi(configs[5])
|
||||||
if err == nil && checkFrequency > 0 {
|
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 {
|
if len(configs) > 6 {
|
||||||
retries, err := strconv.Atoi(configs[6])
|
retries, err := strconv.Atoi(configs[6])
|
||||||
if err == nil && retries > 0 {
|
if err == nil && retries > 0 {
|
||||||
maxRetries = retries
|
rp.maxRetries = retries
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rp.poollist = rediss.NewClusterClient(&rediss.ClusterOptions{
|
rp.poollist = rediss.NewClusterClient(&rediss.ClusterOptions{
|
||||||
Addrs: strings.Split(rp.savePath, ";"),
|
Addrs: strings.Split(rp.savePath, ";"),
|
||||||
Password: rp.password,
|
Password: rp.password,
|
||||||
PoolSize: rp.poolsize,
|
PoolSize: rp.poolsize,
|
||||||
IdleTimeout: idleTimeout,
|
IdleTimeout: rp.idleTimeout,
|
||||||
IdleCheckFrequency: idleCheckFrequency,
|
IdleCheckFrequency: rp.idleCheckFrequency,
|
||||||
MaxRetries: maxRetries,
|
MaxRetries: rp.maxRetries,
|
||||||
})
|
})
|
||||||
return rp.poollist.Ping().Err()
|
return rp.poollist.Ping().Err()
|
||||||
}
|
}
|
||||||
|
@ -107,13 +107,16 @@ func (rs *SessionStore) SessionRelease(w http.ResponseWriter) {
|
|||||||
|
|
||||||
// Provider redis_sentinel session provider
|
// Provider redis_sentinel session provider
|
||||||
type Provider struct {
|
type Provider struct {
|
||||||
maxlifetime int64
|
maxlifetime int64
|
||||||
savePath string
|
savePath string
|
||||||
poolsize int
|
poolsize int
|
||||||
password string
|
password string
|
||||||
dbNum int
|
dbNum int
|
||||||
poollist *redis.Client
|
idleTimeout time.Duration
|
||||||
masterName string
|
idleCheckFrequency time.Duration
|
||||||
|
maxRetries int
|
||||||
|
poollist *redis.Client
|
||||||
|
masterName string
|
||||||
}
|
}
|
||||||
|
|
||||||
// SessionInit init redis_sentinel session
|
// SessionInit init redis_sentinel session
|
||||||
@ -157,37 +160,34 @@ func (rp *Provider) SessionInit(maxlifetime int64, savePath string) error {
|
|||||||
} else {
|
} else {
|
||||||
rp.masterName = "mymaster"
|
rp.masterName = "mymaster"
|
||||||
}
|
}
|
||||||
var idleTimeout time.Duration = 0
|
|
||||||
if len(configs) > 5 {
|
if len(configs) > 5 {
|
||||||
timeout, err := strconv.Atoi(configs[4])
|
timeout, err := strconv.Atoi(configs[4])
|
||||||
if err == nil && timeout > 0 {
|
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 {
|
if len(configs) > 6 {
|
||||||
checkFrequency, err := strconv.Atoi(configs[5])
|
checkFrequency, err := strconv.Atoi(configs[5])
|
||||||
if err == nil && checkFrequency > 0 {
|
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 {
|
if len(configs) > 7 {
|
||||||
retries, err := strconv.Atoi(configs[6])
|
retries, err := strconv.Atoi(configs[6])
|
||||||
if err == nil && retries > 0 {
|
if err == nil && retries > 0 {
|
||||||
maxRetries = retries
|
rp.maxRetries = retries
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rp.poollist = redis.NewFailoverClient(&redis.FailoverOptions{
|
rp.poollist = redis.NewFailoverClient(&redis.FailoverOptions{
|
||||||
SentinelAddrs: strings.Split(rp.savePath, ";"),
|
SentinelAddrs: strings.Split(rp.savePath, ";"),
|
||||||
Password: rp.password,
|
Password: rp.password,
|
||||||
PoolSize: rp.poolsize,
|
PoolSize: rp.poolsize,
|
||||||
DB: rp.dbNum,
|
DB: rp.dbNum,
|
||||||
MasterName: rp.masterName,
|
MasterName: rp.masterName,
|
||||||
IdleTimeout: idleTimeout,
|
IdleTimeout: rp.idleTimeout,
|
||||||
IdleCheckFrequency: idleCheckFrequency,
|
IdleCheckFrequency: rp.idleCheckFrequency,
|
||||||
MaxRetries: maxRetries,
|
MaxRetries: rp.maxRetries,
|
||||||
})
|
})
|
||||||
|
|
||||||
return rp.poollist.Ping().Err()
|
return rp.poollist.Ping().Err()
|
||||||
|
Loading…
Reference in New Issue
Block a user