mirror of
https://gitee.com/johng/gf
synced 2026-07-01 03:21:22 +08:00
improve package gsession
This commit is contained in:
@ -108,7 +108,13 @@ func (s *Session) Set(key string, value interface{}) error {
|
||||
}
|
||||
|
||||
// Sets batch sets the session using map.
|
||||
// Deprecated, use SetMap instead.
|
||||
func (s *Session) Sets(data map[string]interface{}) error {
|
||||
return s.SetMap(data)
|
||||
}
|
||||
|
||||
// SetMap batch sets the session using map.
|
||||
func (s *Session) SetMap(data map[string]interface{}) error {
|
||||
s.init()
|
||||
if err := s.manager.storage.SetMap(s.id, data, s.manager.ttl); err != nil {
|
||||
if err == ErrorDisabled {
|
||||
@ -122,16 +128,18 @@ func (s *Session) Sets(data map[string]interface{}) error {
|
||||
}
|
||||
|
||||
// Remove removes key along with its value from this session.
|
||||
func (s *Session) Remove(key string) error {
|
||||
func (s *Session) Remove(keys ...string) error {
|
||||
if s.id == "" {
|
||||
return nil
|
||||
}
|
||||
s.init()
|
||||
if err := s.manager.storage.Remove(s.id, key); err != nil {
|
||||
if err == ErrorDisabled {
|
||||
s.data.Remove(key)
|
||||
} else {
|
||||
return err
|
||||
for _, key := range keys {
|
||||
if err := s.manager.storage.Remove(s.id, key); err != nil {
|
||||
if err == ErrorDisabled {
|
||||
s.data.Remove(key)
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
s.dirty = true
|
||||
|
||||
Reference in New Issue
Block a user