@@ -8,10 +8,11 @@ import (
88 "fmt"
99 "time"
1010
11+ "code.gitea.io/gitea/modules/graceful"
1112 "code.gitea.io/gitea/modules/nosql"
1213
1314 "gitea.com/go-chi/cache"
14- "github.com/go-redis/redis/v7 "
15+ "github.com/go-redis/redis/v8 "
1516 "github.com/unknwon/com"
1617)
1718
@@ -28,28 +29,28 @@ type RedisCacher struct {
2829func (c * RedisCacher ) Put (key string , val interface {}, expire int64 ) error {
2930 key = c .prefix + key
3031 if expire == 0 {
31- if err := c .c .Set (key , com .ToStr (val ), 0 ).Err (); err != nil {
32+ if err := c .c .Set (graceful . GetManager (). HammerContext (), key , com .ToStr (val ), 0 ).Err (); err != nil {
3233 return err
3334 }
3435 } else {
3536 dur , err := time .ParseDuration (com .ToStr (expire ) + "s" )
3637 if err != nil {
3738 return err
3839 }
39- if err = c .c .Set (key , com .ToStr (val ), dur ).Err (); err != nil {
40+ if err = c .c .Set (graceful . GetManager (). HammerContext (), key , com .ToStr (val ), dur ).Err (); err != nil {
4041 return err
4142 }
4243 }
4344
4445 if c .occupyMode {
4546 return nil
4647 }
47- return c .c .HSet (c .hsetName , key , "0" ).Err ()
48+ return c .c .HSet (graceful . GetManager (). HammerContext (), c .hsetName , key , "0" ).Err ()
4849}
4950
5051// Get gets cached value by given key.
5152func (c * RedisCacher ) Get (key string ) interface {} {
52- val , err := c .c .Get (c .prefix + key ).Result ()
53+ val , err := c .c .Get (graceful . GetManager (). HammerContext (), c .prefix + key ).Result ()
5354 if err != nil {
5455 return nil
5556 }
@@ -59,58 +60,58 @@ func (c *RedisCacher) Get(key string) interface{} {
5960// Delete deletes cached value by given key.
6061func (c * RedisCacher ) Delete (key string ) error {
6162 key = c .prefix + key
62- if err := c .c .Del (key ).Err (); err != nil {
63+ if err := c .c .Del (graceful . GetManager (). HammerContext (), key ).Err (); err != nil {
6364 return err
6465 }
6566
6667 if c .occupyMode {
6768 return nil
6869 }
69- return c .c .HDel (c .hsetName , key ).Err ()
70+ return c .c .HDel (graceful . GetManager (). HammerContext (), c .hsetName , key ).Err ()
7071}
7172
7273// Incr increases cached int-type value by given key as a counter.
7374func (c * RedisCacher ) Incr (key string ) error {
7475 if ! c .IsExist (key ) {
7576 return fmt .Errorf ("key '%s' not exist" , key )
7677 }
77- return c .c .Incr (c .prefix + key ).Err ()
78+ return c .c .Incr (graceful . GetManager (). HammerContext (), c .prefix + key ).Err ()
7879}
7980
8081// Decr decreases cached int-type value by given key as a counter.
8182func (c * RedisCacher ) Decr (key string ) error {
8283 if ! c .IsExist (key ) {
8384 return fmt .Errorf ("key '%s' not exist" , key )
8485 }
85- return c .c .Decr (c .prefix + key ).Err ()
86+ return c .c .Decr (graceful . GetManager (). HammerContext (), c .prefix + key ).Err ()
8687}
8788
8889// IsExist returns true if cached value exists.
8990func (c * RedisCacher ) IsExist (key string ) bool {
90- if c .c .Exists (c .prefix + key ).Val () == 1 {
91+ if c .c .Exists (graceful . GetManager (). HammerContext (), c .prefix + key ).Val () == 1 {
9192 return true
9293 }
9394
9495 if ! c .occupyMode {
95- c .c .HDel (c .hsetName , c .prefix + key )
96+ c .c .HDel (graceful . GetManager (). HammerContext (), c .hsetName , c .prefix + key )
9697 }
9798 return false
9899}
99100
100101// Flush deletes all cached data.
101102func (c * RedisCacher ) Flush () error {
102103 if c .occupyMode {
103- return c .c .FlushDB ().Err ()
104+ return c .c .FlushDB (graceful . GetManager (). HammerContext () ).Err ()
104105 }
105106
106- keys , err := c .c .HKeys (c .hsetName ).Result ()
107+ keys , err := c .c .HKeys (graceful . GetManager (). HammerContext (), c .hsetName ).Result ()
107108 if err != nil {
108109 return err
109110 }
110- if err = c .c .Del (keys ... ).Err (); err != nil {
111+ if err = c .c .Del (graceful . GetManager (). HammerContext (), keys ... ).Err (); err != nil {
111112 return err
112113 }
113- return c .c .Del (c .hsetName ).Err ()
114+ return c .c .Del (graceful . GetManager (). HammerContext (), c .hsetName ).Err ()
114115}
115116
116117// StartAndGC starts GC routine based on config string settings.
@@ -132,7 +133,7 @@ func (c *RedisCacher) StartAndGC(opts cache.Options) error {
132133 }
133134 }
134135
135- return c .c .Ping ().Err ()
136+ return c .c .Ping (graceful . GetManager (). HammerContext () ).Err ()
136137}
137138
138139func init () {
0 commit comments