Simplify logic of New function

This commit is contained in:
Juan Calderon-Perez
2023-04-08 18:42:55 -07:00
parent ca239f0353
commit 5a120d6807

View File

@@ -30,7 +30,7 @@ func New(config ...Config) *Storage {
options.PoolSize = cfg.PoolSize options.PoolSize = cfg.PoolSize
db := redis.NewClient(options) db := redis.NewClient(options)
} else if cfg.EnableFailover { } else if cfg.EnableFailover {
options := &redis.FailoverOptions{ db := redis.NewFailoverClient(&redis.FailoverOptions{
MasterName: cfg.MasterName, MasterName: cfg.MasterName,
SentinelAddrs: cfg.SentinelHosts, SentinelAddrs: cfg.SentinelHosts,
ClientName: cfg.ClientName, ClientName: cfg.ClientName,
@@ -40,18 +40,16 @@ func New(config ...Config) *Storage {
Password: cfg.Password, Password: cfg.Password,
TLSConfig: cfg.TLSConfig, TLSConfig: cfg.TLSConfig,
PoolSize: cfg.PoolSize, PoolSize: cfg.PoolSize,
} })
db := redis.NewFailoverClient(options)
} else { } else {
options := &redis.Options{ db := redis.NewClient(&redis.Options{
Addr: fmt.Sprintf("%s:%d", cfg.Host, cfg.Port), Addr: fmt.Sprintf("%s:%d", cfg.Host, cfg.Port),
DB: cfg.Database, DB: cfg.Database,
Username: cfg.Username, Username: cfg.Username,
Password: cfg.Password, Password: cfg.Password,
TLSConfig: cfg.TLSConfig, TLSConfig: cfg.TLSConfig,
PoolSize: cfg.PoolSize, PoolSize: cfg.PoolSize,
} })
db := redis.NewClient(options)
} }
// Test connection // Test connection