File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Expand file tree Collapse file tree 2 files changed +21
-1
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.
@@ -244,7 +247,7 @@ var (
244247func 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 ())
Original file line number Diff line number Diff 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})
You can’t perform that action at this time.
0 commit comments