We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent fd5b2fe commit 381adf7Copy full SHA for 381adf7
cache/redis/redis.go
@@ -13,6 +13,8 @@ import (
13
14
var ErrNotFound = fmt.Errorf("not found")
15
16
+const healthCheckTimeout = 2 * time.Second
17
+
18
type Redis struct {
19
client *redis.Client
20
}
@@ -175,3 +177,18 @@ func (r *Redis) Reconnect(ctx context.Context, host string) error {
175
177
func (r *Redis) Close() error {
176
178
return r.client.Close()
179
180
181
+func (r *Redis) HealthCheck() error {
182
+ if r == nil {
183
+ return nil
184
+ }
185
186
+ ctx, cancel := context.WithTimeout(context.Background(), healthCheckTimeout)
187
+ defer cancel()
188
189
+ if !r.IsAvailable(ctx) {
190
+ return errors.New("redis is not available")
191
192
193
194
+}
0 commit comments