Skip to content

Commit

Permalink
Make universal options functions public (redis#1250)
Browse files Browse the repository at this point in the history
* Make universal options functions public
  • Loading branch information
furkansenharputlu authored Jan 29, 2020
1 parent 2f96fd1 commit 8a0ab1a
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions universal.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ type UniversalOptions struct {
MasterName string
}

func (o *UniversalOptions) cluster() *ClusterOptions {
// Cluster returns cluster options created from the universal options.
func (o *UniversalOptions) Cluster() *ClusterOptions {
if len(o.Addrs) == 0 {
o.Addrs = []string{"127.0.0.1:6379"}
}
Expand Down Expand Up @@ -84,7 +85,8 @@ func (o *UniversalOptions) cluster() *ClusterOptions {
}
}

func (o *UniversalOptions) failover() *FailoverOptions {
// Failover returns failover options created from the universal options.
func (o *UniversalOptions) Failover() *FailoverOptions {
if len(o.Addrs) == 0 {
o.Addrs = []string{"127.0.0.1:26379"}
}
Expand Down Expand Up @@ -118,7 +120,8 @@ func (o *UniversalOptions) failover() *FailoverOptions {
}
}

func (o *UniversalOptions) simple() *Options {
// Simple returns basic options created from the universal options.
func (o *UniversalOptions) Simple() *Options {
addr := "127.0.0.1:6379"
if len(o.Addrs) > 0 {
addr = o.Addrs[0]
Expand Down Expand Up @@ -183,9 +186,9 @@ var _ UniversalClient = (*Ring)(nil)
// 3. otherwise, a single-node redis Client will be returned.
func NewUniversalClient(opts *UniversalOptions) UniversalClient {
if opts.MasterName != "" {
return NewFailoverClient(opts.failover())
return NewFailoverClient(opts.Failover())
} else if len(opts.Addrs) > 1 {
return NewClusterClient(opts.cluster())
return NewClusterClient(opts.Cluster())
}
return NewClient(opts.simple())
return NewClient(opts.Simple())
}

0 comments on commit 8a0ab1a

Please sign in to comment.