File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed
Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff 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.
@@ -246,7 +249,7 @@ var (
246249func NewUniversalClient (opts * UniversalOptions ) UniversalClient {
247250 if opts .MasterName != "" {
248251 return NewFailoverClient (opts .Failover ())
249- } else if len (opts .Addrs ) > 1 {
252+ } else if len (opts .Addrs ) > 1 || opts . IsClusterMode {
250253 return NewClusterClient (opts .Cluster ())
251254 }
252255 return NewClient (opts .Simple ())
Original file line number Diff line number Diff line change @@ -61,7 +61,6 @@ var _ = Describe("UniversalClient", func() {
6161 Expect (a ).ToNot (Panic ())
6262 })
6363
64-
6564 It ("should connect to failover servers on slaves when readonly Options is ok" , func () {
6665 client = redis .NewUniversalClient (& redis.UniversalOptions {
6766 MasterName : sentinelName ,
@@ -85,6 +84,21 @@ var _ = Describe("UniversalClient", func() {
8584
8685 })
8786
87+ It ("should connect to clusters if IsClusterMode is set even if only a single address is provided" , Label ("NonRedisEnterprise" ), func () {
88+ client = redis .NewUniversalClient (& redis.UniversalOptions {
89+ Addrs : []string {cluster .addrs ()[0 ]},
90+ IsClusterMode : true ,
91+ })
92+ _ , ok := client .(* redis.ClusterClient )
93+ Expect (ok ).To (BeTrue (), "expected a ClusterClient" )
94+ })
8895
96+ It ("should return all slots after instantiating UniversalClient with IsClusterMode" , Label ("NonRedisEnterprise" ), func () {
97+ client = redis .NewUniversalClient (& redis.UniversalOptions {
98+ Addrs : []string {cluster .addrs ()[0 ]},
99+ IsClusterMode : true ,
100+ })
101+ Expect (client .ClusterSlots (ctx ).Val ()).To (HaveLen (3 ))
102+ })
89103})
90104
You can’t perform that action at this time.
0 commit comments