From 094705e87d5ef53a88fa29186252ecd8564774bb Mon Sep 17 00:00:00 2001 From: Lykin <137850705+tiny-craft@users.noreply.github.com> Date: Sun, 18 Feb 2024 22:28:50 +0800 Subject: [PATCH] fix: can not switch db in sentinel mode #144 --- backend/services/connection_service.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/backend/services/connection_service.go b/backend/services/connection_service.go index 1b3dba3..5f7732d 100644 --- a/backend/services/connection_service.go +++ b/backend/services/connection_service.go @@ -144,9 +144,6 @@ func (c *connectionService) buildOption(config types.ConnectionConfig) (*redis.O option.Addr = fmt.Sprintf("%s:%d", config.Addr, config.Port) } } - if config.LastDB > 0 { - option.DB = config.LastDB - } if sshClient != nil { option.Dialer = func(ctx context.Context, network, addr string) (net.Conn, error) { return sshClient.Dial(network, addr) @@ -181,6 +178,10 @@ func (c *connectionService) createRedisClient(config types.ConnectionConfig) (re option.Password = config.Sentinel.Password } + if config.LastDB > 0 { + option.DB = config.LastDB + } + rdb := redis.NewClient(option) if config.Cluster.Enable { // connect to cluster