/
cluster.go
38 lines (32 loc) · 925 Bytes
/
cluster.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
package redisfx
import (
"context"
"github.com/guoyk93/ufx"
"github.com/redis/go-redis/extra/redisotel/v9"
"github.com/redis/go-redis/v9"
)
type ClusterParams struct {
URL string `json:"url"`
}
func DecodeClusterParams(conf ufx.Conf) (params ClusterParams, err error) {
err = conf.Bind(¶ms, "redis", "cluster")
return
}
func NewClusterOptions(params ClusterParams) (*redis.ClusterOptions, error) {
return redis.ParseClusterURL(params.URL)
}
func NewClusterClient(opts *redis.ClusterOptions) (client *redis.ClusterClient, err error) {
client = redis.NewClusterClient(opts)
if err = redisotel.InstrumentTracing(client); err != nil {
return
}
if err = redisotel.InstrumentMetrics(client); err != nil {
return
}
return
}
func AddCheckerForClusterClient(client *redis.ClusterClient, v ufx.Prober) {
v.AddChecker("redis-cluster", func(ctx context.Context) error {
return client.Ping(ctx).Err()
})
}