diff --git a/asynq.go b/asynq.go index 86ddb9d..37585e7 100644 --- a/asynq.go +++ b/asynq.go @@ -485,6 +485,7 @@ func parseRedisURI(u *url.URL) (RedisConnOpt, error) { } redisConnOpt.Addr = u.Host + redisConnOpt.Username = u.User.Username() redisConnOpt.Password = password redisConnOpt.DB = db @@ -509,7 +510,7 @@ func parseRedisSocketURI(u *url.URL) (RedisConnOpt, error) { if v, ok := u.User.Password(); ok { password = v } - return RedisClientOpt{Network: "unix", Addr: u.Path, DB: db, Password: password}, nil + return RedisClientOpt{Network: "unix", Addr: u.Path, DB: db, Username: u.User.Username(), Password: password}, nil } func parseRedisSentinelURI(u *url.URL) (RedisConnOpt, error) { diff --git a/asynq_test.go b/asynq_test.go index 1147682..fddf64b 100644 --- a/asynq_test.go +++ b/asynq_test.go @@ -109,22 +109,50 @@ func TestParseRedisURI(t *testing.T) { "redis://localhost:6379/3", RedisClientOpt{Addr: "localhost:6379", DB: 3}, }, + { + "redis://:@localhost:6379", + RedisClientOpt{Addr: "localhost:6379"}, + }, + { + "redis://myusername:@localhost:6379", + RedisClientOpt{Addr: "localhost:6379", Username: "myusername"}, + }, { "redis://:mypassword@localhost:6379", RedisClientOpt{Addr: "localhost:6379", Password: "mypassword"}, }, + { + "redis://myusername:mypassword@localhost:6379", + RedisClientOpt{Addr: "localhost:6379", Username: "myusername", Password: "mypassword"}, + }, { "redis://:mypassword@127.0.0.1:6379/11", RedisClientOpt{Addr: "127.0.0.1:6379", Password: "mypassword", DB: 11}, }, + { + "redis://myusername:mypassword@localhost:6379/11", + RedisClientOpt{Addr: "localhost:6379", Username: "myusername", Password: "mypassword", DB: 11}, + }, { "redis-socket:///var/run/redis/redis.sock", RedisClientOpt{Network: "unix", Addr: "/var/run/redis/redis.sock"}, }, + { + "redis-socket://:@/var/run/redis/redis.sock", + RedisClientOpt{Network: "unix", Addr: "/var/run/redis/redis.sock"}, + }, + { + "redis-socket://myusername:@/var/run/redis/redis.sock", + RedisClientOpt{Network: "unix", Addr: "/var/run/redis/redis.sock", Username: "myusername"}, + }, { "redis-socket://:mypassword@/var/run/redis/redis.sock", RedisClientOpt{Network: "unix", Addr: "/var/run/redis/redis.sock", Password: "mypassword"}, }, + { + "redis-socket://myusername:mypassword@/var/run/redis/redis.sock", + RedisClientOpt{Network: "unix", Addr: "/var/run/redis/redis.sock", Username: "myusername", Password: "mypassword"}, + }, { "redis-socket:///var/run/redis/redis.sock?db=7", RedisClientOpt{Network: "unix", Addr: "/var/run/redis/redis.sock", DB: 7},