Skip to content

Commit

Permalink
Merge pull request #74 from uknth/dep-upgrade
Browse files Browse the repository at this point in the history
fix: add health check for redis-cache
  • Loading branch information
uknth authored Jan 21, 2024
2 parents dcb8e3f + 07f3019 commit fe6d078
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions data/cache/redis/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"time"

redis "github.com/redis/go-redis/v9"
"github.com/unbxd/go-base/v2/errors"
"github.com/unbxd/go-base/v2/log"
)

Expand Down Expand Up @@ -259,6 +260,15 @@ func NewRedisCache(
// create client
cc := redis.NewClient(ch.opt)

sc := cc.Ping(context.Background())
if sc.Err() != nil {
return nil, errors.Wrapf(
sc.Err(),
"failed to connect to redis. addr: %s",
addr,
)
}

ch.cc = cc
return &Cache{ch}, nil
}

0 comments on commit fe6d078

Please # to comment.