Skip to content

Commit 1683069

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 1683069

File tree

1 file changed

+65
-2
lines changed

1 file changed

+65
-2
lines changed

command.go

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,64 @@ 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+
"ping": {},
49+
"psubscribe": {},
50+
"psync": {},
51+
"publish": {},
52+
"pubsub": {},
53+
"punsubscribe": {},
54+
"quit": {},
55+
"readonly": {},
56+
"readwrite": {},
57+
"replconf": {},
58+
"replicaof": {},
59+
"request_policy:all_nodes": {},
60+
"request_policy:all_shards": {},
61+
"reset": {},
62+
"role": {},
63+
"save": {},
64+
"script": {},
65+
"select": {},
66+
"shutdown": {},
67+
"slaveof": {},
68+
"slowlog": {},
69+
"subscribe": {},
70+
"swapdb": {},
71+
"sync": {},
72+
"unsubscribe": {},
73+
"unwatch": {},
74+
"xgroup": {},
75+
"xinfo": {},
76+
}
77+
2078
type Cmder interface {
2179
// command name.
2280
// e.g. "set k v ex 10" -> "set", "cluster info" -> "cluster".
@@ -83,9 +141,14 @@ func cmdFirstKeyPos(cmd Cmder) int {
83141
return int(pos)
84142
}
85143

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

0 commit comments

Comments
 (0)