summaryrefslogtreecommitdiffstats
path: root/modules/session
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2021-02-10 22:28:32 +0100
committerGitHub <noreply@github.com>2021-02-10 21:28:32 +0000
commitac97ea573c1b10d03e72775e8f74b9fe5453bfc8 (patch)
tree99fa7488782a2a6c4362c49e4cdf04594c662ca3 /modules/session
parent4cffc46f651205b9d7eb0b1df46dd6117c6d95e9 (diff)
downloadgitea-ac97ea573c1b10d03e72775e8f74b9fe5453bfc8.tar.gz
gitea-ac97ea573c1b10d03e72775e8f74b9fe5453bfc8.zip
[Vendor] Update go-redis to v8.5.0 (#13749)
* Update go-redis to v8.4.0 * github.com/go-redis/redis/v8 v8.4.0 -> v8.5.0 * Apply suggestions from code review Co-authored-by: zeripath <art27@cantab.net> * TODO * Use the Queue termination channel as the default context for pushes Signed-off-by: Andrew Thornton <art27@cantab.net> * missed one Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: zeripath <art27@cantab.net>
Diffstat (limited to 'modules/session')
-rw-r--r--modules/session/redis.go27
1 files changed, 16 insertions, 11 deletions
diff --git a/modules/session/redis.go b/modules/session/redis.go
index 55e7a85168..334418bd7e 100644
--- a/modules/session/redis.go
+++ b/modules/session/redis.go
@@ -21,10 +21,11 @@ import (
"sync"
"time"
+ "code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/nosql"
"gitea.com/go-chi/session"
- "github.com/go-redis/redis/v7"
+ "github.com/go-redis/redis/v8"
)
// RedisStore represents a redis session store implementation.
@@ -90,7 +91,7 @@ func (s *RedisStore) Release() error {
return err
}
- return s.c.Set(s.prefix+s.sid, string(data), s.duration).Err()
+ return s.c.Set(graceful.GetManager().HammerContext(), s.prefix+s.sid, string(data), s.duration).Err()
}
// Flush deletes all session data.
@@ -127,20 +128,20 @@ func (p *RedisProvider) Init(maxlifetime int64, configs string) (err error) {
}
p.c = nosql.GetManager().GetRedisClient(uri.String())
- return p.c.Ping().Err()
+ return p.c.Ping(graceful.GetManager().ShutdownContext()).Err()
}
// Read returns raw session store by session ID.
func (p *RedisProvider) Read(sid string) (session.RawStore, error) {
psid := p.prefix + sid
if !p.Exist(sid) {
- if err := p.c.Set(psid, "", p.duration).Err(); err != nil {
+ if err := p.c.Set(graceful.GetManager().HammerContext(), psid, "", p.duration).Err(); err != nil {
return nil, err
}
}
var kv map[interface{}]interface{}
- kvs, err := p.c.Get(psid).Result()
+ kvs, err := p.c.Get(graceful.GetManager().HammerContext(), psid).Result()
if err != nil {
return nil, err
}
@@ -158,13 +159,13 @@ func (p *RedisProvider) Read(sid string) (session.RawStore, error) {
// Exist returns true if session with given ID exists.
func (p *RedisProvider) Exist(sid string) bool {
- v, err := p.c.Exists(p.prefix + sid).Result()
+ v, err := p.c.Exists(graceful.GetManager().HammerContext(), p.prefix+sid).Result()
return err == nil && v == 1
}
// Destroy deletes a session by session ID.
func (p *RedisProvider) Destroy(sid string) error {
- return p.c.Del(p.prefix + sid).Err()
+ return p.c.Del(graceful.GetManager().HammerContext(), p.prefix+sid).Err()
}
// Regenerate regenerates a session store from old session ID to new one.
@@ -176,17 +177,17 @@ func (p *RedisProvider) Regenerate(oldsid, sid string) (_ session.RawStore, err
return nil, fmt.Errorf("new sid '%s' already exists", sid)
} else if !p.Exist(oldsid) {
// Make a fake old session.
- if err = p.c.Set(poldsid, "", p.duration).Err(); err != nil {
+ if err = p.c.Set(graceful.GetManager().HammerContext(), poldsid, "", p.duration).Err(); err != nil {
return nil, err
}
}
- if err = p.c.Rename(poldsid, psid).Err(); err != nil {
+ if err = p.c.Rename(graceful.GetManager().HammerContext(), poldsid, psid).Err(); err != nil {
return nil, err
}
var kv map[interface{}]interface{}
- kvs, err := p.c.Get(psid).Result()
+ kvs, err := p.c.Get(graceful.GetManager().HammerContext(), psid).Result()
if err != nil {
return nil, err
}
@@ -205,7 +206,11 @@ func (p *RedisProvider) Regenerate(oldsid, sid string) (_ session.RawStore, err
// Count counts and returns number of sessions.
func (p *RedisProvider) Count() int {
- return int(p.c.DBSize().Val())
+ size, err := p.c.DBSize(graceful.GetManager().HammerContext()).Result()
+ if err != nil {
+ return 0
+ }
+ return int(size)
}
// GC calls GC to clean expired sessions.