2
0
mirror of https://github.com/hibiken/asynq.git synced 2026-06-17 20:59:13 +08:00

fix: parse DB number from redis-sentinel URI path (#669)

Previously, parseRedisSentinelURI ignored the /dbnumber path segment,
making it impossible to connect to any DB other than 0 via sentinel URIs.

This adds DB extraction from the URI path, consistent with how
parseRedisURI already handles it for redis:// and rediss:// schemes.

Closes #669
This commit is contained in:
Jiale Lin
2026-03-21 11:20:52 -07:00
parent d704b68a42
commit 07898eade0
2 changed files with 32 additions and 2 deletions

View File

@@ -148,6 +148,23 @@ func TestParseRedisURI(t *testing.T) {
SentinelPassword: "mypassword",
},
},
{
"redis-sentinel://localhost:5000,localhost:5001,localhost:5002/3?master=mymaster",
RedisFailoverClientOpt{
MasterName: "mymaster",
SentinelAddrs: []string{"localhost:5000", "localhost:5001", "localhost:5002"},
DB: 3,
},
},
{
"redis-sentinel://:mypassword@localhost:5000,localhost:5001,localhost:5002/7?master=mymaster",
RedisFailoverClientOpt{
MasterName: "mymaster",
SentinelAddrs: []string{"localhost:5000", "localhost:5001", "localhost:5002"},
SentinelPassword: "mypassword",
DB: 7,
},
},
}
for _, tc := range tests {
@@ -188,6 +205,10 @@ func TestParseRedisURIErrors(t *testing.T) {
"non integer for db numbers for socket",
"redis-socket:///some/path/to/redis?db=one",
},
{
"non integer for db number for sentinel",
"redis-sentinel://localhost:5000/abc?master=mymaster",
},
}
for _, tc := range tests {