Browse Source

refactor: reduce duplication in redis.NewClient creation

Address code review feedback by defining redis.Options once and
conditionally setting TLSConfig instead of duplicating the entire
NewClient call.
pull/7591/head
chrislu 2 days ago
parent
commit
0e034eab80
  1. 23
      weed/filer/redis2/redis_store.go

23
weed/filer/redis2/redis_store.go

@ -40,6 +40,12 @@ func (store *Redis2Store) Initialize(configuration util.Configuration, prefix st
}
func (store *Redis2Store) initialize(hostPort string, username string, password string, database int, keyPrefix string, superLargeDirectories []string, enableMtls bool, caCertPath string, clientCertPath string, clientKeyPath string) (err error) {
opt := &redis.Options{
Addr: hostPort,
Username: username,
Password: password,
DB: database,
}
if enableMtls {
clientCert, err := tls.LoadX509KeyPair(clientCertPath, clientKeyPath)
if err != nil {
@ -61,27 +67,14 @@ func (store *Redis2Store) initialize(hostPort string, username string, password
glog.Fatalf("Error parsing redis host and port from %s: %v", hostPort, err)
}
tlsConfig := &tls.Config{
opt.TLSConfig = &tls.Config{
Certificates: []tls.Certificate{clientCert},
RootCAs: caCertPool,
ServerName: redisHost,
MinVersion: tls.VersionTLS12,
}
store.Client = redis.NewClient(&redis.Options{
Addr: hostPort,
Username: username,
Password: password,
DB: database,
TLSConfig: tlsConfig,
})
} else {
store.Client = redis.NewClient(&redis.Options{
Addr: hostPort,
Username: username,
Password: password,
DB: database,
})
}
store.Client = redis.NewClient(opt)
store.keyPrefix = keyPrefix
store.loadSuperLargeDirectories(superLargeDirectories)
return

Loading…
Cancel
Save