@@ -18,6 +18,7 @@ import (
1818 "time"
1919
2020 "github.com/FZambia/sentinel"
21+ "github.com/distribution/distribution/v3/configuration"
2122 "github.com/distribution/reference"
2223 "github.com/docker/distribution"
2324 "github.com/docker/distribution/configuration"
@@ -518,13 +519,15 @@ func (app *App) configureRedis(configuration *configuration.Configuration) {
518519 redisOptions = append (redisOptions , redis .DialUseTLS (true ))
519520 }
520521
522+ sentinelOptions := redisOptions
523+
521524 if configuration .Redis .SentinelMasterSet != "" {
522525 sntnl := & sentinel.Sentinel {
523526 Addrs : strings .Split (configuration .Redis .Addr , "," ),
524527 MasterName : configuration .Redis .SentinelMasterSet ,
525528 Dial : func (addr string ) (redis.Conn , error ) {
526529 c , err := redis .Dial ("tcp" , addr ,
527- redisOptions ... )
530+ sentinelOptions ... )
528531 if err != nil {
529532 return nil , err
530533 }
@@ -553,6 +556,16 @@ func (app *App) configureRedis(configuration *configuration.Configuration) {
553556 }
554557 }
555558
559+ // Parse auth configurations only for master if service deployed as sentinel mode
560+ username := configuration .Redis .Username
561+ password := configuration .Redis .Password
562+ if password != "" {
563+ if username != "" {
564+ redisOptions = append (redisOptions , redis .DialUsername (username ))
565+ }
566+ redisOptions = append (redisOptions , redis .DialPassword (password ))
567+ }
568+
556569 pool := & redis.Pool {
557570 Dial : func () (redis.Conn , error ) {
558571 // TODO(stevvooe): Yet another use case for contextual timing.
@@ -580,16 +593,6 @@ func (app *App) configureRedis(configuration *configuration.Configuration) {
580593 done (err )
581594 return nil , err
582595 }
583-
584- // authorize the connection
585- if configuration .Redis .Password != "" {
586- if _ , err = conn .Do ("AUTH" , configuration .Redis .Password ); err != nil {
587- defer conn .Close ()
588- done (err )
589- return nil , err
590- }
591- }
592-
593596 // select the database to use
594597 if configuration .Redis .DB != 0 {
595598 if _ , err = conn .Do ("SELECT" , configuration .Redis .DB ); err != nil {
0 commit comments