-
Notifications
You must be signed in to change notification settings - Fork 18
/
system.go
47 lines (36 loc) · 1.02 KB
/
system.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
package redis
import (
"context"
"github.com/go-redis/redis/v9"
"github.com/circleci/ex/system"
)
// Load will create a new Redis client, and wire it into the provided System with
// default lifecycle management and observability.
func Load(o Options, sys *system.System) *redis.Client {
client := New(o)
sys.AddCleanup(func(_ context.Context) error {
return client.Close()
})
name := o.Name
if name == "" {
name = "redis"
}
sys.AddHealthCheck(NewHealthCheck(client, name))
sys.AddMetrics(NewMetrics(name, client))
return client
}
// LoadCluster will create a new Redis cluster client, and wire it into the provided System with
// default lifecycle management and observability.
func LoadCluster(o ClusterOptions, sys *system.System) *redis.ClusterClient {
client := NewCluster(o)
sys.AddCleanup(func(_ context.Context) error {
return client.Close()
})
name := o.Name
if name == "" {
name = "redis"
}
sys.AddHealthCheck(NewHealthCheck(client, name))
sys.AddMetrics(NewMetrics(name, client))
return client
}