diff --git a/redis/conn.go b/redis/conn.go index 753644b1..dc445a06 100644 --- a/redis/conn.go +++ b/redis/conn.go @@ -332,7 +332,10 @@ func DialURLContext(ctx context.Context, rawurl string, options ...DialOption) ( return nil, err } - if u.Scheme != "redis" && u.Scheme != "rediss" { + switch u.Scheme { + case "redis", "rediss", "valkey", "valkeys": + // valid scheme + default: return nil, fmt.Errorf("invalid redis URL scheme: %s", u.Scheme) } @@ -386,7 +389,7 @@ func DialURLContext(ctx context.Context, rawurl string, options ...DialOption) ( return nil, fmt.Errorf("invalid database: %s", u.Path[1:]) } - options = append(options, DialUseTLS(u.Scheme == "rediss")) + options = append(options, DialUseTLS(u.Scheme == "rediss" || u.Scheme == "valkeys")) return DialContext(ctx, "tcp", address, options...) } diff --git a/redis/conn_test.go b/redis/conn_test.go index b94f0f42..414b7ef3 100644 --- a/redis/conn_test.go +++ b/redis/conn_test.go @@ -624,6 +624,22 @@ var dialErrors = []struct { "redis:foo//localhost:6379", "invalid redis URL, url is opaque: redis:foo//localhost:6379", }, + { + "valkey://localhost:6379/abc123", + "invalid database: abc123", + }, + { + "valkeys://localhost:6379/abc123", + "invalid database: abc123", + }, + { + "valkey:foo//localhost:6379", + "invalid redis URL, url is opaque: valkey:foo//localhost:6379", + }, + { + "valkeys:foo//localhost:6379", + "invalid redis URL, url is opaque: valkeys:foo//localhost:6379", + }, } func TestDialURLErrors(t *testing.T) {