-
Notifications
You must be signed in to change notification settings - Fork 0
/
redis.go
63 lines (53 loc) · 1.26 KB
/
redis.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package probes
import (
"context"
"time"
"github.com/redis/go-redis/v9"
)
type VSHNRedis struct {
redisClient redis.Client
Service string
Name string
Namespace string
HighAvailable bool
Organization string
ServiceLevel string
}
func (redis VSHNRedis) Close() error {
// Redis requires context here
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
defer cancel()
if redis.redisClient.ClientID(ctx) != nil {
redis.redisClient.Close()
}
return nil
}
func (redis VSHNRedis) GetInfo() ProbeInfo {
return ProbeInfo{
Service: redis.Service,
Name: redis.Name,
Namespace: redis.Namespace,
HighAvailable: false,
Organization: redis.Organization,
ServiceLevel: redis.ServiceLevel,
}
}
func (redis VSHNRedis) Probe(ctx context.Context) error {
_, err := redis.redisClient.Ping(ctx).Result()
if err != nil {
return err
}
return nil
}
func NewRedis(service, name, namespace, organization, sla string, ha bool, opts redis.Options) (*VSHNRedis, error) {
client := redis.NewClient(&opts)
return &VSHNRedis{
redisClient: *client,
Service: service,
Name: name,
Namespace: namespace,
HighAvailable: ha,
Organization: organization,
ServiceLevel: sla,
}, nil
}