From 21d183853d65251b5f734c6071bd40ea43cca0e5 Mon Sep 17 00:00:00 2001 From: Alex Arnell Date: Wed, 27 Jul 2022 11:12:38 -0700 Subject: [PATCH] deal with Redis 4,5 & 6 compatibility issues --- cmdutil/redispool/redispool.go | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/cmdutil/redispool/redispool.go b/cmdutil/redispool/redispool.go index da370b00..f6f5ac67 100644 --- a/cmdutil/redispool/redispool.go +++ b/cmdutil/redispool/redispool.go @@ -4,6 +4,7 @@ package redispool import ( "context" + "net/url" "os" "time" @@ -71,10 +72,29 @@ func (c Config) Pools() ([]*redis.Pool, error) { func newPool(cfg Config) *redis.Pool { return &redis.Pool{ DialContext: func(ctx context.Context) (redis.Conn, error) { + connURL, err := url.Parse(cfg.URL) + if err != nil { + return nil, err + } + + if connURL.User != nil { + password, ok := connURL.User.Password() + + // For Heroku Redis we need to strip the username from the URL. After + // the release of Redis 6, clients began to support the new AUTH + // command that uses 2 arguments. Heroku Redis removed the `h` username + // from connection urls, but only on new addons. Existing addons do not + // have the `h` removed so we must check for and remove it here. + // See https://devcenter.heroku.com/changelog-items/1932 + if connURL.User.Username() == "h" && ok { + connURL.User = url.UserPassword("", password) + } + } + // For Heroku Redis we need to skip the TLS verification, see // https://devcenter.heroku.com/articles/heroku-redis#connecting-in-go // redis.DialTLSSkipVerify will have no effect for non-TLS connections. - conn, err := redis.DialURLContext(ctx, cfg.URL, redis.DialTLSSkipVerify(true)) + conn, err := redis.DialURLContext(ctx, connURL.String(), redis.DialTLSSkipVerify(true)) if err != nil { return nil, err }