Properly separate Redis and Sentinel password

This commit is contained in:
Akhyar Amarullah 2022-09-27 16:38:53 +07:00
parent bda90ac732
commit 5111aa4f21
2 changed files with 18 additions and 2 deletions

View File

@ -109,6 +109,8 @@ func makeRedisConnOpt(cfg *Config) (asynq.RedisConnOpt, error) {
}
connOpt := res.(asynq.RedisFailoverClientOpt) // safe to type-assert
connOpt.TLSConfig = makeTLSConfig(cfg)
connOpt.SentinelPassword = connOpt.Password // password from asynq.ParseRedisURI should be used for sentinel
connOpt.Password = cfg.RedisPassword // override parsed password with value from config
return connOpt, nil
}

View File

@ -100,13 +100,27 @@ func TestMakeRedisConnOpt(t *testing.T) {
{
desc: "With redis-sentinel URL",
cfg: &Config{
RedisURL: "redis-sentinel://:secretpassword@localhost:5000,localhost:5001,localhost:5002?master=mymaster",
RedisURL: "redis-sentinel://:sentinelpassword@localhost:5000,localhost:5001,localhost:5002?master=mymaster",
},
want: asynq.RedisFailoverClientOpt{
MasterName: "mymaster",
SentinelAddrs: []string{
"localhost:5000", "localhost:5001", "localhost:5002"},
Password: "secretpassword", // FIXME: Shouldn't this be SentinelPassword instead?
SentinelPassword: "sentinelpassword",
},
},
{
desc: "With redis-sentinel URL and password",
cfg: &Config{
RedisURL: "redis-sentinel://:sentinelpassword@localhost:5000,localhost:5001,localhost:5002?master=mymaster",
RedisPassword: "redispassword",
},
want: asynq.RedisFailoverClientOpt{
MasterName: "mymaster",
SentinelAddrs: []string{
"localhost:5000", "localhost:5001", "localhost:5002"},
SentinelPassword: "sentinelpassword",
Password: "redispassword",
},
},
{