Skip to content

Commit 7c977ea

Browse files
committed
fix(keylessCommands): Add list of keyless commands
Add list of keyless Commands based on the Commands output for redis 8
1 parent c368e7e commit 7c977ea

File tree

1 file changed

+64
-2
lines changed

1 file changed

+64
-2
lines changed

command.go

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,63 @@ import (
1717
"github.com/redis/go-redis/v9/internal/util"
1818
)
1919

20+
// keylessCommands contains Redis commands that have empty key specifications (9th slot empty)
21+
// Only includes core Redis commands, excludes FT.*, ts.*, timeseries.*, search.* and subcommands
22+
var keylessCommands = map[string]struct{}{
23+
"acl": {},
24+
"asking": {},
25+
"auth": {},
26+
"bgrewriteaof": {},
27+
"bgsave": {},
28+
"client": {},
29+
"cluster": {},
30+
"config": {},
31+
"debug": {},
32+
"discard": {},
33+
"echo": {},
34+
"exec": {},
35+
"failover": {},
36+
"function": {},
37+
"hello": {},
38+
"latency": {},
39+
"lolwut": {},
40+
"memory": {},
41+
"module": {},
42+
"monitor": {},
43+
"multi": {},
44+
"nondeterministic_output": {},
45+
"nondeterministic_output_order": {},
46+
"object": {},
47+
"pfselftest": {},
48+
"psubscribe": {},
49+
"psync": {},
50+
"publish": {},
51+
"pubsub": {},
52+
"punsubscribe": {},
53+
"quit": {},
54+
"readonly": {},
55+
"readwrite": {},
56+
"replconf": {},
57+
"replicaof": {},
58+
"request_policy:all_nodes": {},
59+
"request_policy:all_shards": {},
60+
"reset": {},
61+
"role": {},
62+
"save": {},
63+
"script": {},
64+
"select": {},
65+
"shutdown": {},
66+
"slaveof": {},
67+
"slowlog": {},
68+
"subscribe": {},
69+
"swapdb": {},
70+
"sync": {},
71+
"unsubscribe": {},
72+
"unwatch": {},
73+
"xgroup": {},
74+
"xinfo": {},
75+
}
76+
2077
type Cmder interface {
2178
// command name.
2279
// e.g. "set k v ex 10" -> "set", "cluster info" -> "cluster".
@@ -83,9 +140,14 @@ func cmdFirstKeyPos(cmd Cmder) int {
83140
return int(pos)
84141
}
85142

86-
switch cmd.Name() {
87-
case "echo", "ping", "command":
143+
name := cmd.Name()
144+
145+
// first check if the command is keyless
146+
if _, ok := keylessCommands[name]; ok {
88147
return 0
148+
}
149+
150+
switch name {
89151
case "eval", "evalsha", "eval_ro", "evalsha_ro":
90152
if cmd.stringArg(2) != "0" {
91153
return 3

0 commit comments

Comments
 (0)