@@ -4,12 +4,11 @@ import (
44 "bytes"
55 "context"
66 "io"
7- "io/ioutil"
87 "strconv"
98 "strings"
109 "time"
1110
12- "github.com/go-redis/redis "
11+ "github.com/redis/ go-redis/v9 "
1312)
1413
1514var (
@@ -61,7 +60,9 @@ func InitRedisClient(addr, password string, db int) error {
6160 DB : db ,
6261 })
6362
64- if _ , err := client .Ping ().Result (); err != nil {
63+ ctx := context .Background ()
64+
65+ if _ , err := client .Ping (ctx ).Result (); err != nil {
6566 return err
6667 }
6768
@@ -94,23 +95,23 @@ func (r *RedisBackend) Length() int {
9495
9596// Close write the temp buffer's content to the groupcache
9697func (r * RedisBackend ) Close () error {
97- _ , err := client .Set (r .Key , r .content .Bytes (), r .expiration .Sub (time .Now ())).Result ()
98+ _ , err := client .Set (r .Ctx , r . Key , r .content .Bytes (), r .expiration .Sub (time .Now ())).Result ()
9899 return err
99100}
100101
101102// Clean performs the purge storage
102103func (r * RedisBackend ) Clean () error {
103- _ , err := client .Del (r .Key ).Result ()
104+ _ , err := client .Del (r .Ctx , r . Key ).Result ()
104105 return err
105106}
106107
107108// GetReader return a reader for the write public response
108109func (r * RedisBackend ) GetReader () (io.ReadCloser , error ) {
109- content , err := client .Get (r .Key ).Result ()
110+ content , err := client .Get (r .Ctx , r . Key ).Result ()
110111 if err != nil {
111112 return nil , err
112113 }
113114
114- rc := ioutil .NopCloser (strings .NewReader (content ))
115+ rc := io .NopCloser (strings .NewReader (content ))
115116 return rc , nil
116117}
0 commit comments