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) {