mirror of
https://github.com/eosswedenorg/thalos
synced 2026-07-02 11:43:40 +02:00
cmd/thalos/server.go: move redis connect code to it's own function and log connection attempt.
This commit is contained in:
parent
1658b3ea99
commit
9dcb8c4f0c
1 changed files with 28 additions and 9 deletions
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"path"
|
"path"
|
||||||
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -262,6 +263,32 @@ func chainInfoOnce(api *eos.API) func() *eos.InfoResp {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ConnectRedis(conf *config.RedisConfig) (*redis.Client, error) {
|
||||||
|
logEntry := log.WithFields(log.Fields{
|
||||||
|
"addr": conf.Addr,
|
||||||
|
"db": conf.DB,
|
||||||
|
})
|
||||||
|
|
||||||
|
if len(conf.User) > 0 {
|
||||||
|
logEntry = logEntry.WithField("user", conf.User)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(conf.Password) > 0 {
|
||||||
|
logEntry = logEntry.WithField("password", strings.Repeat("*", len(conf.Password)))
|
||||||
|
}
|
||||||
|
|
||||||
|
logEntry.Info("Connecting to redis")
|
||||||
|
|
||||||
|
rdb := redis.NewClient(&redis.Options{
|
||||||
|
Addr: conf.Addr,
|
||||||
|
Username: conf.User,
|
||||||
|
Password: conf.Password,
|
||||||
|
DB: conf.DB,
|
||||||
|
})
|
||||||
|
|
||||||
|
return rdb, rdb.Ping(context.Background()).Err()
|
||||||
|
}
|
||||||
|
|
||||||
func serverCmd(cmd *cobra.Command, args []string) {
|
func serverCmd(cmd *cobra.Command, args []string) {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
|
@ -333,15 +360,7 @@ func serverCmd(cmd *cobra.Command, args []string) {
|
||||||
notify.UseServices(telegram)
|
notify.UseServices(telegram)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Connect to redis
|
rdb, err := ConnectRedis(&conf.Redis)
|
||||||
rdb := redis.NewClient(&redis.Options{
|
|
||||||
Addr: conf.Redis.Addr,
|
|
||||||
Username: conf.Redis.User,
|
|
||||||
Password: conf.Redis.Password,
|
|
||||||
DB: conf.Redis.DB,
|
|
||||||
})
|
|
||||||
|
|
||||||
err = rdb.Ping(context.Background()).Err()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithError(err).Fatal("Failed to connect to redis")
|
log.WithError(err).Fatal("Failed to connect to redis")
|
||||||
return
|
return
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue