Skip to content

Commit

Permalink
fix(redis): init and close client in method
Browse files Browse the repository at this point in the history
  • Loading branch information
romain-jeannoutot committed Apr 14, 2022
1 parent d51b4e9 commit 25f035d
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions redis/jwk.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,25 @@ import (
)

type JwkFetcher struct {
client *redis.Client
options *redis.Options
}

func NewJwkFetcher() *JwkFetcher {
return &JwkFetcher{
client: redis.NewClient(&redis.Options{
options: &redis.Options{
Addr: env.Redis.Addr,
Username: env.Redis.User,
Password: env.Redis.Password,
}),
},
}
}

func (f *JwkFetcher) FetchJwk(ctx context.Context, kid string) (*visiauth.Jwk, error) {
client := redis.NewClient(f.options)
defer client.Close()

var jwk visiauth.Jwk
if err := f.client.Get(ctx, kid).Scan(&jwk); err != nil {
if err := client.Get(ctx, kid).Scan(&jwk); err != nil {
return nil, err
}

Expand Down

0 comments on commit 25f035d

Please sign in to comment.