-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(os/gsession): add session reset function. #3726
base: master
Are you sure you want to change the base?
Changes from 10 commits
5f6843c
999f822
5c0a9ce
8f7f13a
f26b5c7
44da506
d132f4e
e2f4563
0435e2a
373b052
8f7c1f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,4 @@ go.work.sum | |
node_modules | ||
.docusaurus | ||
output | ||
config/* |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ package gsession | |
|
||
import ( | ||
"context" | ||
"fmt" | ||
"time" | ||
|
||
"github.com/gogf/gf/v2/container/gmap" | ||
|
@@ -82,6 +83,7 @@ func (s *Session) init() error { | |
// | ||
// NOTE that this function must be called ever after a session request done. | ||
func (s *Session) Close() error { | ||
fmt.Println("") | ||
if s.manager.storage == nil { | ||
return nil | ||
} | ||
|
@@ -155,6 +157,33 @@ func (s *Session) Remove(keys ...string) (err error) { | |
return nil | ||
} | ||
|
||
func (s *Session) RegenSession(delOld ...bool) (newSid string, err error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 请描述增加此方法的必要性,例如需要解决什么样的业务场景痛点? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 没有这个方法,sessionId始终不能过期。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个怎么说,还需修改什么吗? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 直接使用 |
||
oldDel := false | ||
if len(delOld) > 0 { | ||
oldDel = delOld[0] | ||
} | ||
if s.id == "" { | ||
if err = s.init(); err != nil { | ||
return newSid, err | ||
} | ||
} else { | ||
if oldDel { | ||
if err = s.RemoveAll(); err != nil { | ||
return newSid, err | ||
} | ||
} | ||
s.id = "" | ||
s.start = false | ||
s.data.Clear() | ||
if err = s.init(); err != nil { | ||
return newSid, err | ||
} | ||
} | ||
newSid = s.id | ||
s.dirty = false | ||
return newSid, err | ||
} | ||
|
||
// RemoveAll deletes all key-value pairs from this session. | ||
func (s *Session) RemoveAll() (err error) { | ||
if s.id == "" { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lxy1151 请先拆分pr,一个pr只做一个事情。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好的,我先处理下