Skip to content

Commit 7d55118

Browse files
reeshijoshijoshirushikeshndyakov
authored
feat: support Elasticache cluster mode by introducing IsClusterMode config param (#3255)
Co-authored-by: Rushikesh Joshi <[email protected]> Co-authored-by: Nedyalko Dyakov <[email protected]>
1 parent d4e74b1 commit 7d55118

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-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.
@@ -244,7 +247,7 @@ var (
244247
func NewUniversalClient(opts *UniversalOptions) UniversalClient {
245248
if opts.MasterName != "" {
246249
return NewFailoverClient(opts.Failover())
247-
} else if len(opts.Addrs) > 1 {
250+
} else if len(opts.Addrs) > 1 || opts.IsClusterMode {
248251
return NewClusterClient(opts.Cluster())
249252
}
250253
return NewClient(opts.Simple())

universal_test.go

+17
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,21 @@ var _ = Describe("UniversalClient", func() {
6060
a := func() { client.FTInfo(ctx, "all").Result() }
6161
Expect(a).ToNot(Panic())
6262
})
63+
64+
It("should connect to clusters if IsClusterMode is set even if only a single address is provided", Label("NonRedisEnterprise"), func() {
65+
client = redis.NewUniversalClient(&redis.UniversalOptions{
66+
Addrs: []string{cluster.addrs()[0]},
67+
IsClusterMode: true,
68+
})
69+
_, ok := client.(*redis.ClusterClient)
70+
Expect(ok).To(BeTrue(), "expected a ClusterClient")
71+
})
72+
73+
It("should return all slots after instantiating UniversalClient with IsClusterMode", Label("NonRedisEnterprise"), func() {
74+
client = redis.NewUniversalClient(&redis.UniversalOptions{
75+
Addrs: []string{cluster.addrs()[0]},
76+
IsClusterMode: true,
77+
})
78+
Expect(client.ClusterSlots(ctx).Val()).To(HaveLen(3))
79+
})
6380
})

0 commit comments

Comments
 (0)