From 1f2350d852e0a3e8aafb0f56278f432536aaa2ab Mon Sep 17 00:00:00 2001 From: Goxiaoy Date: Tue, 14 May 2024 23:15:57 +0800 Subject: [PATCH] bugfix: fix CalcKeys with COMMAND --- internal/commands/keys.go | 4 +++- internal/commands/keys_test.go | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/internal/commands/keys.go b/internal/commands/keys.go index be9ab578..3b1a5eef 100644 --- a/internal/commands/keys.go +++ b/internal/commands/keys.go @@ -16,7 +16,9 @@ func CalcKeys(argv []string) (cmaName string, group string, keys []string, keysI group = "unknown" cmaName = strings.ToUpper(argv[0]) if _, ok := containers[cmaName]; ok { - cmaName = fmt.Sprintf("%s-%s", cmaName, strings.ToUpper(argv[1])) + if len(argv) > 1 { + cmaName = fmt.Sprintf("%s-%s", cmaName, strings.ToUpper(argv[1])) + } } cmd, ok := redisCommands[cmaName] if !ok { diff --git a/internal/commands/keys_test.go b/internal/commands/keys_test.go index e6c7bd74..9b9de6f9 100644 --- a/internal/commands/keys_test.go +++ b/internal/commands/keys_test.go @@ -40,6 +40,12 @@ func TestCalcKeys(t *testing.T) { if cmd != "ZUNIONSTORE" || group != "SORTED_SET" || !testEq(keys, []string{"key", "key1", "key2"}) { t.Errorf("CalcKeys(ZUNIONSTORE key 2 key1 key2) failed. cmd=%s, group=%s, keys=%v", cmd, group, keys) } + + // COMMAND + cmd, group, keys, _ = CalcKeys([]string{"COMMAND"}) + if cmd != "COMMAND" || group != "SERVER" || !testEq(keys, []string{}) { + t.Errorf("CalcKeys(COMMAND) failed. cmd=%s, group=%s, keys=%v", cmd, group, keys) + } } func TestKeyHash(t *testing.T) {