mirror of
https://github.com/astaxie/beego.git
synced 2025-06-12 19:40:40 +00:00
Add additional options to redis session prov
Adding option for frequency of checking timed out connections as well as an option to specify retries. These changes make redis provider more stable since connection problems are becoming fewer. Since redigo does not have this options and since redis_sentinel and redis_cluster are using go-redis as a client, this commit changes from redigo to go-redis for redis session provider. Added tests for redis session provider as well.
This commit is contained in:
@ -34,7 +34,7 @@ package redis_sentinel
|
||||
|
||||
import (
|
||||
"github.com/astaxie/beego/pkg/session"
|
||||
"github.com/go-redis/redis"
|
||||
"github.com/go-redis/redis/v7"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
@ -157,6 +157,27 @@ 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
|
||||
}
|
||||
}
|
||||
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
|
||||
}
|
||||
}
|
||||
var maxRetries = 0
|
||||
if len(configs) > 7 {
|
||||
retries, err := strconv.Atoi(configs[6])
|
||||
if err == nil && retries > 0 {
|
||||
maxRetries = retries
|
||||
}
|
||||
}
|
||||
|
||||
rp.poollist = redis.NewFailoverClient(&redis.FailoverOptions{
|
||||
SentinelAddrs: strings.Split(rp.savePath, ";"),
|
||||
@ -164,6 +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,
|
||||
})
|
||||
|
||||
return rp.poollist.Ping().Err()
|
||||
|
Reference in New Issue
Block a user