Skip to content
This repository has been archived by the owner on Mar 31, 2024. It is now read-only.

Commit

Permalink
update getting context
Browse files Browse the repository at this point in the history
  • Loading branch information
gamalan committed Mar 8, 2022
1 parent cb6e2c4 commit f330325
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.vscode
.idea
.idea
vendor
10 changes: 7 additions & 3 deletions storageredis.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func (rd *RedisStorage) Provision(ctx caddy.Context) error {
rd.Logger = ctx.Logger(rd).Sugar()
rd.GetConfigValue()
rd.Logger.Info("TLS Storage are using Redis, on " + rd.Address)
if err := rd.BuildRedisClient(); err != nil {
if err := rd.BuildRedisClient(ctx.Context); err != nil {
return err
}
return nil
Expand Down Expand Up @@ -306,8 +306,12 @@ func (rd *RedisStorage) prefixKey(key string) string {
}

// GetRedisStorage build RedisStorage with it's client
func (rd *RedisStorage) BuildRedisClient() error {
rd.ctx = context.Background()
func (rd *RedisStorage) BuildRedisClient(ctx context.Context) error {
if ctx != nil {
rd.ctx = ctx
} else {
rd.ctx = context.Background()
}
redisClient := redis.NewClient(&redis.Options{
Addr: rd.Address,
Username: rd.Username,
Expand Down
2 changes: 1 addition & 1 deletion storageredis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func setupRedisEnv(t *testing.T) *RedisStorage {

rd := new(RedisStorage)
rd.GetConfigValue()
err := rd.BuildRedisClient()
err := rd.BuildRedisClient(nil)

// skip test if no redis storage
if err != nil {
Expand Down

0 comments on commit f330325

Please sign in to comment.