mirror of
https://github.com/gofiber/storage.git
synced 2025-10-05 16:48:25 +08:00
Simplify logic of New function
This commit is contained in:
@@ -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
|
||||||
|
Reference in New Issue
Block a user