Skip to content

Commit cf4e8a0

Browse files
feat: support Elasticache cluster mode by introducing IsClusterMode config param
1 parent 1b4abd6 commit cf4e8a0

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

universal.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ type UniversalOptions struct {
6969
DisableIndentity bool
7070
IdentitySuffix string
7171
UnstableResp3 bool
72+
73+
// IsClusterMode can be used when only one Addrs is provided (e.g. Elasticache supports setting up cluster mode with configuration endpoint).
74+
IsClusterMode bool
7275
}
7376

7477
// Cluster returns cluster options created from the universal options.
@@ -243,7 +246,7 @@ var (
243246
func NewUniversalClient(opts *UniversalOptions) UniversalClient {
244247
if opts.MasterName != "" {
245248
return NewFailoverClient(opts.Failover())
246-
} else if len(opts.Addrs) > 1 {
249+
} else if len(opts.Addrs) > 1 || opts.IsClusterMode {
247250
return NewClusterClient(opts.Cluster())
248251
}
249252
return NewClient(opts.Simple())

universal_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,13 @@ var _ = Describe("UniversalClient", func() {
3838
})
3939
Expect(client.Ping(ctx).Err()).NotTo(HaveOccurred())
4040
})
41+
42+
It("should connect to clusters if IsClusterMode is set even if only a single address is provided", Label("NonRedisEnterprise"), func() {
43+
client = redis.NewUniversalClient(&redis.UniversalOptions{
44+
Addrs: []string{cluster.addrs()[0]},
45+
IsClusterMode: true,
46+
})
47+
_, ok := client.(*redis.ClusterClient)
48+
Expect(ok).To(BeTrue(), "expected a ClusterClient")
49+
})
4150
})

0 commit comments

Comments
 (0)