mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 12:20:54 +00:00
add sess_ledis select db config
This commit is contained in:
parent
934dd2e8d2
commit
29d98731c6
@ -2,6 +2,8 @@ package session
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/astaxie/beego/session"
|
"github.com/astaxie/beego/session"
|
||||||
@ -74,19 +76,29 @@ func (ls *LedisSessionStore) SessionRelease(w http.ResponseWriter) {
|
|||||||
type LedisProvider struct {
|
type LedisProvider struct {
|
||||||
maxlifetime int64
|
maxlifetime int64
|
||||||
savePath string
|
savePath string
|
||||||
|
db int
|
||||||
}
|
}
|
||||||
|
|
||||||
// init ledis session
|
// init ledis session
|
||||||
// savepath like ledis server saveDataPath,pool size
|
// savepath like ledis server saveDataPath,pool size
|
||||||
// e.g. 127.0.0.1:6379,100,astaxie
|
// e.g. 127.0.0.1:6379,100,astaxie
|
||||||
func (lp *LedisProvider) SessionInit(maxlifetime int64, savePath string) error {
|
func (lp *LedisProvider) SessionInit(maxlifetime int64, savePath string) error {
|
||||||
|
var err error
|
||||||
lp.maxlifetime = maxlifetime
|
lp.maxlifetime = maxlifetime
|
||||||
lp.savePath = savePath
|
configs := strings.Split(savepath, ",")
|
||||||
|
if len(configs) == 1 {
|
||||||
|
lp.savePath = configs[0]
|
||||||
|
} else if len(configs) == 2 {
|
||||||
|
lp.savePath = configs[0]
|
||||||
|
lp.db, err = strconv.Atoi(configs[1])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
cfg := new(config.Config)
|
cfg := new(config.Config)
|
||||||
cfg.DataDir = lp.savePath
|
cfg.DataDir = lp.savePath
|
||||||
var err error
|
|
||||||
nowLedis, err := ledis.Open(cfg)
|
nowLedis, err := ledis.Open(cfg)
|
||||||
c, err = nowLedis.Select(0)
|
c, err = nowLedis.Select(lp.db)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
println(err)
|
println(err)
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user