-
Notifications
You must be signed in to change notification settings - Fork 0
/
checker.go
39 lines (29 loc) · 900 Bytes
/
checker.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package redis
import "github.com/dimiro1/health"
// Redis is a interface used to abstract the access of the Version string
type Redis interface {
GetVersion() (string, error)
}
// Checker is a checker that check a given redis
type Checker struct {
Redis Redis
}
// NewChecker returns a new redis.Checker
func NewChecker(network, addr string) Checker {
return Checker{Redis: NewRedigo(network, addr)}
}
// NewCheckerWithRedis returns a new redis.Checker configured with a custom Redis implementation
func NewCheckerWithRedis(redis Redis) Checker {
return Checker{Redis: redis}
}
// Check obtain the version string from redis info command
func (c Checker) Check() health.Health {
health := health.NewHealth()
version, err := c.Redis.GetVersion()
if err != nil {
health.Down().AddInfo("error", err.Error())
return health
}
health.Up().AddInfo("version", version)
return health
}