1
0
mirror of https://github.com/astaxie/beego.git synced 2025-06-14 04:10:38 +00:00

make stmt cache smaller

This commit is contained in:
Ming Deng
2020-10-10 21:34:02 +08:00
parent 8e37fe3b78
commit 1dffa20435
23 changed files with 89 additions and 75 deletions

View File

@ -31,14 +31,16 @@
//
// more docs: http://beego.me/docs/module/session.md
package redis_cluster
import (
"net/http"
"strconv"
"strings"
"sync"
"time"
"github.com/astaxie/beego/session"
rediss "github.com/go-redis/redis"
"time"
)
var redispder = &Provider{}
@ -101,7 +103,7 @@ func (rs *SessionStore) SessionRelease(w http.ResponseWriter) {
return
}
c := rs.p
c.Set(rs.sid, string(b), time.Duration(rs.maxlifetime) * time.Second)
c.Set(rs.sid, string(b), time.Duration(rs.maxlifetime)*time.Second)
}
// Provider redis_cluster session provider
@ -146,10 +148,10 @@ func (rp *Provider) SessionInit(maxlifetime int64, savePath string) error {
} else {
rp.dbNum = 0
}
rp.poollist = rediss.NewClusterClient(&rediss.ClusterOptions{
Addrs: strings.Split(rp.savePath, ";"),
Password: rp.password,
Password: rp.password,
PoolSize: rp.poolsize,
})
return rp.poollist.Ping().Err()
@ -186,15 +188,15 @@ func (rp *Provider) SessionExist(sid string) bool {
// SessionRegenerate generate new sid for redis_cluster session
func (rp *Provider) SessionRegenerate(oldsid, sid string) (session.Store, error) {
c := rp.poollist
if existed, err := c.Exists(oldsid).Result(); err != nil || existed == 0 {
// oldsid doesn't exists, set the new sid directly
// ignore error here, since if it return error
// the existed value will be 0
c.Set(sid, "", time.Duration(rp.maxlifetime) * time.Second)
c.Set(sid, "", time.Duration(rp.maxlifetime)*time.Second)
} else {
c.Rename(oldsid, sid)
c.Expire(sid, time.Duration(rp.maxlifetime) * time.Second)
c.Expire(sid, time.Duration(rp.maxlifetime)*time.Second)
}
return rp.SessionRead(sid)
}

View File

@ -33,13 +33,14 @@
package redis_sentinel
import (
"github.com/astaxie/beego/session"
"github.com/go-redis/redis"
"net/http"
"strconv"
"strings"
"sync"
"time"
"github.com/astaxie/beego/session"
"github.com/go-redis/redis"
)
var redispder = &Provider{}

View File

@ -369,8 +369,7 @@ func TestFileSessionStore_SessionRelease(t *testing.T) {
t.Error(err)
}
s.Set(i,i)
s.Set(i, i)
s.SessionRelease(nil)
}
@ -384,4 +383,4 @@ func TestFileSessionStore_SessionRelease(t *testing.T) {
t.Error()
}
}
}
}