From 4a0807e4636ec78e6beab185bf0a63aa535662cc Mon Sep 17 00:00:00 2001 From: tiny-craft <137850705+tiny-craft@users.noreply.github.com> Date: Sun, 15 Oct 2023 22:38:41 +0800 Subject: [PATCH] chore: forbid rename key in cluster mode --- backend/services/connection_service.go | 8 ++++++-- backend/types/connection.go | 5 ----- backend/utils/string/convert.go | 5 ++++- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/backend/services/connection_service.go b/backend/services/connection_service.go index 83fcc55..f5e2656 100644 --- a/backend/services/connection_service.go +++ b/backend/services/connection_service.go @@ -1396,8 +1396,12 @@ func (c *connectionService) RenameKey(connName string, db int, key, newKey strin return } - _, err = client.RenameNX(ctx, key, newKey).Result() - if err != nil { + if _, ok := client.(*redis.ClusterClient); ok { + resp.Msg = "RENAME not support in cluster mode yet" + return + } + + if _, err = client.RenameNX(ctx, key, newKey).Result(); err != nil { resp.Msg = err.Error() return } diff --git a/backend/types/connection.go b/backend/types/connection.go index 4ea7d05..9ef43da 100644 --- a/backend/types/connection.go +++ b/backend/types/connection.go @@ -30,11 +30,6 @@ type Connection struct { type Connections []Connection -type ConnectionGroup struct { - GroupName string `json:"groupName" yaml:"group_name"` - Connections []Connection `json:"connections" yaml:"connections"` -} - type ConnectionDB struct { Name string `json:"name"` Index int `json:"index"` diff --git a/backend/utils/string/convert.go b/backend/utils/string/convert.go index 83503f8..57b8ba3 100644 --- a/backend/utils/string/convert.go +++ b/backend/utils/string/convert.go @@ -14,6 +14,7 @@ import ( "strconv" "strings" "tinyrdm/backend/types" + "unicode/utf8" ) // ConvertTo convert string to specified type @@ -187,7 +188,9 @@ func decodeJson(str string) (string, bool) { func decodeBase64(str string) (string, bool) { if decodedStr, err := base64.StdEncoding.DecodeString(str); err == nil { - return string(decodedStr), true + if s := string(decodedStr); utf8.ValidString(s) { + return s, true + } } return str, false }