Skip to content

Commit 65a8f4a

Browse files
authored
Merge branch 'master' into ndyakov/extract-benchmark-tests
2 parents 3c6b79e + 7d55118 commit 65a8f4a

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

universal.go

Lines changed: 4 additions & 1 deletion
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

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

0 commit comments

Comments
 (0)