diff --git a/stores/memory/store.go b/stores/memory/store.go index db9fae2..fe5625c 100644 --- a/stores/memory/store.go +++ b/stores/memory/store.go @@ -149,7 +149,7 @@ func (s *Store) SetMulti(id string, data map[string]interface{}) error { } // Delete deletes a key from session. -func (s *Store) Delete(id string, key string) error { +func (s *Store) Delete(id string, keys ...string) error { s.mu.Lock() defer s.mu.Unlock() @@ -157,7 +157,10 @@ func (s *Store) Delete(id string, key string) error { if !ok { return ErrInvalidSession } - delete(s.sessions[id], key) + + for _, k := range keys { + delete(s.sessions[id], k) + } return nil } diff --git a/stores/postgres/postgres.go b/stores/postgres/postgres.go index f735c6d..30740b4 100644 --- a/stores/postgres/postgres.go +++ b/stores/postgres/postgres.go @@ -15,6 +15,7 @@ import ( "fmt" "time" + "github.com/lib/pq" _ "github.com/lib/pq" ) @@ -203,8 +204,8 @@ func (s *Store) SetMulti(id string, data map[string]interface{}) (err error) { } // Delete deletes a key from redis session hashmap. -func (s *Store) Delete(id string, key string) error { - res, err := s.q.delete.Exec(id, key) +func (s *Store) Delete(id string, keys ...string) error { + res, err := s.q.delete.Exec(id, pq.Array(keys)) if err != nil { return err } @@ -388,7 +389,7 @@ func (s *Store) prepareQueries() (*queries, error) { return nil, err } - q.delete, err = s.db.Prepare(fmt.Sprintf("UPDATE %s SET data = data - $2 WHERE id=$1", s.opt.Table)) + q.delete, err = s.db.Prepare(fmt.Sprintf("UPDATE %s SET data = data #- $2 WHERE id=$1", s.opt.Table)) if err != nil { return nil, err } diff --git a/stores/redis/store.go b/stores/redis/store.go index 5a00601..086978f 100644 --- a/stores/redis/store.go +++ b/stores/redis/store.go @@ -184,8 +184,8 @@ func (s *Store) SetMulti(id string, data map[string]interface{}) error { } // Delete deletes a key from redis session hashmap. -func (s *Store) Delete(id string, key string) error { - return s.client.HDel(s.clientCtx, s.prefix+id, key).Err() +func (s *Store) Delete(id string, keys ...string) error { + return s.client.HDel(s.clientCtx, s.prefix+id, keys...).Err() } // Clear clears session in redis. diff --git a/stores/securecookie/secure_cookie.go b/stores/securecookie/secure_cookie.go index 8bb4571..ed50940 100644 --- a/stores/securecookie/secure_cookie.go +++ b/stores/securecookie/secure_cookie.go @@ -202,15 +202,17 @@ func (s *Store) Flush(cv string) (string, error) { // Delete deletes a field from session. Once called, Flush() should be // called to retrieve the updated, unflushed values and written to the cookie // externally. -func (s *Store) Delete(cv, key string) error { +func (s *Store) Delete(cv string, keys ...string) error { // Decode current cookie vals, err := s.decode(cv) if err != nil { return ErrInvalidSession } - // Delete given key in current values. - delete(vals, key) + for _, k := range keys { + // Delete given key in current values. + delete(vals, k) + } // Create session map if doesn't exist. s.mu.Lock()