diff --git a/.gitignore b/.gitignore index 8cd0df3..84bfef2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .vscode -.idea \ No newline at end of file +.idea +vendor \ No newline at end of file diff --git a/storageredis.go b/storageredis.go index 5a3f551..d2d60e6 100644 --- a/storageredis.go +++ b/storageredis.go @@ -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 @@ -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, diff --git a/storageredis_test.go b/storageredis_test.go index 8088b06..d01eca8 100644 --- a/storageredis_test.go +++ b/storageredis_test.go @@ -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 {