-
Notifications
You must be signed in to change notification settings - Fork 18
/
redis.go
47 lines (39 loc) · 880 Bytes
/
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
package redis
import (
"crypto/tls"
"crypto/x509"
"net"
"strconv"
"github.com/go-redis/redis/v8"
"github.com/circleci/ex/config/secret"
)
type Options struct {
Host string
Port int
User string
Password secret.String
// Optional
TLS bool
CAFunc func() *x509.CertPool
}
// New will only construct a new Redis client with the provided options. It is the caller's
// responsibility to close it at the right time.
func New(o Options) *redis.Client {
opts := &redis.Options{
Addr: net.JoinHostPort(o.Host, strconv.FormatInt(int64(o.Port), 10)),
Username: o.User,
Password: o.Password.Value(),
}
if o.TLS {
var rootCAs *x509.CertPool
if o.CAFunc != nil {
rootCAs = o.CAFunc()
}
opts.TLSConfig = &tls.Config{
MinVersion: tls.VersionTLS12,
ServerName: o.Host,
RootCAs: rootCAs,
}
}
return redis.NewClient(opts)
}