Skip to content

Commit

Permalink
Use Get/Set instead of Rename when Regenerate session id (#23975) (#2…
Browse files Browse the repository at this point in the history
…3983)

Backport #23975 by @wxiaoguang

Do not use Rename here, because the old sid and new sid may be in
different redis cluster slot.

Fix #23869

Co-authored-by: wxiaoguang <[email protected]>
  • Loading branch information
GiteaBot and wxiaoguang authored Apr 7, 2023
1 parent f317186 commit 3a7cb1a
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions modules/session/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,21 @@ func (p *RedisProvider) Regenerate(oldsid, sid string) (_ session.RawStore, err
}
}

if err = p.c.Rename(graceful.GetManager().HammerContext(), poldsid, psid).Err(); err != nil {
// do not use Rename here, because the old sid and new sid may be in different redis cluster slot.
kvs, err := p.c.Get(graceful.GetManager().HammerContext(), poldsid).Result()
if err != nil {
return nil, err
}

var kv map[interface{}]interface{}
kvs, err := p.c.Get(graceful.GetManager().HammerContext(), psid).Result()
if err != nil {
if err = p.c.Del(graceful.GetManager().HammerContext(), poldsid).Err(); err != nil {
return nil, err
}

if err = p.c.Set(graceful.GetManager().HammerContext(), psid, kvs, p.duration).Err(); err != nil {
return nil, err
}

var kv map[interface{}]interface{}
if len(kvs) == 0 {
kv = make(map[interface{}]interface{})
} else {
Expand Down

0 comments on commit 3a7cb1a

Please sign in to comment.