fix: can not switch db in sentinel mode #144

This commit is contained in:
Lykin 2024-02-18 22:28:50 +08:00
parent f1e1a89baf
commit 094705e87d
1 changed files with 4 additions and 3 deletions

View File

@ -144,9 +144,6 @@ func (c *connectionService) buildOption(config types.ConnectionConfig) (*redis.O
option.Addr = fmt.Sprintf("%s:%d", config.Addr, config.Port) option.Addr = fmt.Sprintf("%s:%d", config.Addr, config.Port)
} }
} }
if config.LastDB > 0 {
option.DB = config.LastDB
}
if sshClient != nil { if sshClient != nil {
option.Dialer = func(ctx context.Context, network, addr string) (net.Conn, error) { option.Dialer = func(ctx context.Context, network, addr string) (net.Conn, error) {
return sshClient.Dial(network, addr) return sshClient.Dial(network, addr)
@ -181,6 +178,10 @@ func (c *connectionService) createRedisClient(config types.ConnectionConfig) (re
option.Password = config.Sentinel.Password option.Password = config.Sentinel.Password
} }
if config.LastDB > 0 {
option.DB = config.LastDB
}
rdb := redis.NewClient(option) rdb := redis.NewClient(option)
if config.Cluster.Enable { if config.Cluster.Enable {
// connect to cluster // connect to cluster