File tree 2 files changed +21
-1
lines changed
2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -69,6 +69,9 @@ type UniversalOptions struct {
69
69
DisableIndentity bool
70
70
IdentitySuffix string
71
71
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
72
75
}
73
76
74
77
// Cluster returns cluster options created from the universal options.
@@ -244,7 +247,7 @@ var (
244
247
func NewUniversalClient (opts * UniversalOptions ) UniversalClient {
245
248
if opts .MasterName != "" {
246
249
return NewFailoverClient (opts .Failover ())
247
- } else if len (opts .Addrs ) > 1 {
250
+ } else if len (opts .Addrs ) > 1 || opts . IsClusterMode {
248
251
return NewClusterClient (opts .Cluster ())
249
252
}
250
253
return NewClient (opts .Simple ())
Original file line number Diff line number Diff line change @@ -60,4 +60,21 @@ var _ = Describe("UniversalClient", func() {
60
60
a := func () { client .FTInfo (ctx , "all" ).Result () }
61
61
Expect (a ).ToNot (Panic ())
62
62
})
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
+ })
63
80
})
You can’t perform that action at this time.
0 commit comments