Skip to content

Commit a852920

Browse files
committed
Support for redis master ACL
Signed-off-by: my036811 <miner.yang@broadcom.com>
1 parent 553d395 commit a852920

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

pkg/redisx/pool.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ func newSentinelPool(configURL *url.URL, config etc.RedisPool) (*redis.Client, e
7070
SentinelAddrs: sentinelURL.Addrs,
7171
DB: sentinelURL.Database,
7272
Password: sentinelURL.Password,
73+
Username: sentinelURL.Username,
7374

7475
DialTimeout: config.ConnectionTimeout,
7576
ReadTimeout: config.ReadTimeout,
@@ -88,6 +89,7 @@ func newSentinelPool(configURL *url.URL, config etc.RedisPool) (*redis.Client, e
8889

8990
type SentinelURL struct {
9091
Password string
92+
Username string
9193
Addrs []string
9294
MonitorName string
9395
Database int
@@ -110,6 +112,7 @@ func ParseSentinelURL(configURL *url.URL) (sentinelURL SentinelURL, err error) {
110112
}
111113

112114
if user := configURL.User; user != nil {
115+
sentinelURL.Username = user.Username()
113116
if password, set := user.Password(); set {
114117
sentinelURL.Password = password
115118
}

pkg/redisx/pool_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ func TestParseSentinelURL(t *testing.T) {
3636
{
3737
configURL: "redis+sentinel://harbor:s3cret@somehost:26379,otherhost:26479/mymaster/3",
3838
expectedSentinelURL: SentinelURL{
39+
Username: "harbor",
3940
Password: "s3cret",
4041
Addrs: []string{
4142
"somehost:26379",
@@ -48,6 +49,7 @@ func TestParseSentinelURL(t *testing.T) {
4849
{
4950
configURL: "redis+sentinel://:s3cret@somehost:26379,otherhost:26479/mymaster/5",
5051
expectedSentinelURL: SentinelURL{
52+
Username: "",
5153
Password: "s3cret",
5254
Addrs: []string{
5355
"somehost:26379",
@@ -60,6 +62,7 @@ func TestParseSentinelURL(t *testing.T) {
6062
{
6163
configURL: "redis+sentinel://:s3cret@somehost:26379,otherhost:26479/mymaster",
6264
expectedSentinelURL: SentinelURL{
65+
Username: "",
6366
Password: "s3cret",
6467
Addrs: []string{
6568
"somehost:26379",
@@ -69,6 +72,19 @@ func TestParseSentinelURL(t *testing.T) {
6972
Database: 0,
7073
},
7174
},
75+
{
76+
configURL: "rediss+sentinel://foo:mypwd@somehost:26379,otherhost:26479/mymaster",
77+
expectedSentinelURL: SentinelURL{
78+
Username: "foo",
79+
Password: "mypwd",
80+
Addrs: []string{
81+
"somehost:26379",
82+
"otherhost:26479",
83+
},
84+
MonitorName: "mymaster",
85+
Database: 0,
86+
},
87+
},
7288
{
7389
configURL: "redis+sentinel://:s3cret@somehost:26379,otherhost:26479/mymaster/X",
7490
expectedError: "invalid redis sentinel URL: invalid database number: X",

0 commit comments

Comments
 (0)