Skip to content

Commit

Permalink
fix(pack): redis session provider loads session data incorrectly
Browse files Browse the repository at this point in the history
  • Loading branch information
cayter committed Jul 17, 2020
1 parent 73e2adb commit 9f4da16
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions pack/internal/sessionstore/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (s *RedisStore) Options(options ginsessions.Options) {
// Save adds a single session to the response.
func (s *RedisStore) Save(r *http.Request, w http.ResponseWriter, session *gorsessions.Session) error {
// Marked for deletion.
if session.Options.MaxAge <= 0 {
if session.Options.MaxAge < 0 {
if err := s.delete(session); err != nil {
return err
}
Expand Down Expand Up @@ -200,21 +200,16 @@ func (s *RedisStore) save(session *gorsessions.Session) error {

// load reads the session from redis and returns true if there is a sessoin data in DB.
func (s *RedisStore) load(session *gorsessions.Session) (bool, error) {
data, err := s.redisClient.Do("GET", s.keyPrefix+session.ID).Result()
data, err := s.redisClient.Get(s.keyPrefix + session.ID).Result()
if err != nil {
return false, err
}

if data == nil {
if data == "" {
return false, nil // no data was associated with this key
}

b, ok := data.([]byte)
if !ok {
return false, nil
}

return true, s.serializer.Deserialize(b, session)
return true, s.serializer.Deserialize([]byte(data), session)
}

// delete removes keys from redis if MaxAge<0
Expand Down

0 comments on commit 9f4da16

Please # to comment.