Skip to content

Commit 5706167

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

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

universal.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ type UniversalOptions struct {
6969
DisableIndentity bool
7070
IdentitySuffix string
7171
UnstableResp3 bool
72+
73+
// This is required because Elasticache supports setting up cluster mode with configuration endpoint. So the check len(Addrs) > 1 is not enough for determining cluster mode.
74+
// If IsClusterMode is true, the client will be created as a cluster client.
75+
IsClusterMode bool
7276
}
7377

7478
// Cluster returns cluster options created from the universal options.
@@ -243,7 +247,7 @@ var (
243247
func NewUniversalClient(opts *UniversalOptions) UniversalClient {
244248
if opts.MasterName != "" {
245249
return NewFailoverClient(opts.Failover())
246-
} else if len(opts.Addrs) > 1 {
250+
} else if len(opts.Addrs) > 1 || opts.IsClusterMode {
247251
return NewClusterClient(opts.Cluster())
248252
}
249253
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)