Skip to content

Commit

Permalink
Fixed# fix redis load method
Browse files Browse the repository at this point in the history
  • Loading branch information
Q1mi committed Jul 9, 2019
1 parent 41eef8d commit 0180cc4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (m *memSession) ID() string {
return m.id
}

func (m *memSession) Load() {
func (m *memSession) Load()(err error) {
return
}

Expand Down
12 changes: 8 additions & 4 deletions redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,19 @@ func (r *redisSession) ID() string {
}

// load session data from redis
func (r *redisSession)Load() {
func (r *redisSession)Load()(err error) {
data, err := r.client.Get(r.id).Result()
if err != nil {
r.data = make(map[string]interface{})
log.Printf("get session data from redis by %s failed, err:%v\n", r.id, err)
return
}
// unmarshal
err = json.Unmarshal([]byte(data), &r.data)
if err != nil {
r.data = make(map[string]interface{})
log.Printf("Unmarshal session data failed, err:%v\n", err)
return
}
return
}


Expand Down Expand Up @@ -143,7 +144,10 @@ func (r *redisSessionMgr) Init(addr string, options ...string) (err error) {
// GetSession load session data and add to sessionMgr
func (r *redisSessionMgr) GetSession(sessionID string) (sd Session, err error) {
sd = NewRedisSession(sessionID, r.client)
sd.Load()
err = sd.Load()
if err != nil {
return
}
r.rwLock.RLock()
r.session[sessionID] = sd
r.rwLock.RUnlock()
Expand Down
2 changes: 1 addition & 1 deletion session.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const (
// Session stores values for a session
type Session interface {
ID() string
Load() // load
Load()error // load
Get(string) (interface{}, error)
Set(string, interface{})
Del(string)
Expand Down

0 comments on commit 0180cc4

Please sign in to comment.