feat(session): support v1

support v1
This commit is contained in:
Alan Xu
2024-08-03 22:57:53 +08:00
committed by Ming Deng
parent 3c6986a5c4
commit 17e916f4a0
14 changed files with 349 additions and 68 deletions

View File

@@ -75,6 +75,13 @@ func (ls *SessionStore) SessionRelease(w http.ResponseWriter) {
c.Expire([]byte(ls.sid), ls.maxlifetime)
}
// SessionReleaseIfPresent is not supported now, because ledis has no this feature like SETXX or atomic operation.
// https://github.com/ledisdb/ledisdb/issues/251
// https://github.com/ledisdb/ledisdb/issues/351
func (ls *SessionStore) SessionReleaseIfPresent(w http.ResponseWriter) {
ls.SessionRelease(w)
}
// Provider ledis session provider
type Provider struct {
maxlifetime int64
@@ -141,8 +148,8 @@ func (lp *Provider) SessionExist(sid string) bool {
func (lp *Provider) SessionRegenerate(oldsid, sid string) (session.Store, error) {
count, _ := c.Exists([]byte(sid))
if count == 0 {
// oldsid doesn't exists, set the new sid directly
// ignore error here, since if it return error
// oldsid doesn't exist, set the new sid directly
// ignore error here, since if it returns error
// the existed value will be 0
c.Set([]byte(sid), []byte(""))
c.Expire([]byte(sid), lp.maxlifetime)
@@ -160,7 +167,7 @@ func (lp *Provider) SessionDestroy(sid string) error {
return nil
}
// SessionGC Impelment method, no used.
// SessionGC Implement method, no used.
func (lp *Provider) SessionGC() {
}