Skip to content

Commit

Permalink
feat: support Elasticache cluster mode by introducing IsClusterMode c…
Browse files Browse the repository at this point in the history
…onfig param
  • Loading branch information
joshirushikesh committed Jan 30, 2025
1 parent 1b4abd6 commit cf4e8a0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion universal.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ type UniversalOptions struct {
DisableIndentity bool
IdentitySuffix string
UnstableResp3 bool

// IsClusterMode can be used when only one Addrs is provided (e.g. Elasticache supports setting up cluster mode with configuration endpoint).
IsClusterMode bool
}

// Cluster returns cluster options created from the universal options.
Expand Down Expand Up @@ -243,7 +246,7 @@ var (
func NewUniversalClient(opts *UniversalOptions) UniversalClient {
if opts.MasterName != "" {
return NewFailoverClient(opts.Failover())
} else if len(opts.Addrs) > 1 {
} else if len(opts.Addrs) > 1 || opts.IsClusterMode {
return NewClusterClient(opts.Cluster())
}
return NewClient(opts.Simple())
Expand Down
9 changes: 9 additions & 0 deletions universal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,13 @@ var _ = Describe("UniversalClient", func() {
})
Expect(client.Ping(ctx).Err()).NotTo(HaveOccurred())
})

It("should connect to clusters if IsClusterMode is set even if only a single address is provided", Label("NonRedisEnterprise"), func() {
client = redis.NewUniversalClient(&redis.UniversalOptions{
Addrs: []string{cluster.addrs()[0]},
IsClusterMode: true,
})
_, ok := client.(*redis.ClusterClient)
Expect(ok).To(BeTrue(), "expected a ClusterClient")
})
})

0 comments on commit cf4e8a0

Please sign in to comment.