Skip to content

Commit d09f1b4

Browse files
committed
Add check-redis --username flag
Supports ACL authentication. https://redis.io/docs/latest/operate/oss_and_stack/management/security/acl/
1 parent 85b1d8b commit d09f1b4

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

check-redis/lib/check-redis.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type redisSetting struct {
1818
Host string `short:"H" long:"host" default:"localhost" description:"Hostname"`
1919
Socket string `short:"s" long:"socket" default:"" description:"Server socket"`
2020
Port string `short:"p" long:"port" default:"6379" description:"Port"`
21+
Username string `short:"U" long:"username" default:"" description:"Username"`
2122
Password string `short:"P" long:"password" default:"" description:"Password"`
2223
Timeout uint64 `short:"t" long:"timeout" default:"5" description:"Dial Timeout in sec"`
2324
}
@@ -77,7 +78,13 @@ func connectRedis(m redisSetting) (redis.Conn, error) {
7778
}
7879

7980
if password != "" {
80-
_, err := c.Do("AUTH", password)
81+
var authArgs []interface{}
82+
if m.Username != "" {
83+
authArgs = []interface{}{m.Username, password}
84+
} else {
85+
authArgs = []interface{}{password}
86+
}
87+
_, err := c.Do("AUTH", authArgs...)
8188
if err != nil {
8289
return nil, fmt.Errorf("couldn't authenticate: %v", err)
8390
}

0 commit comments

Comments
 (0)