From 8a0ab1aaa7c3817f3116d91c17d0ccd52a2ad179 Mon Sep 17 00:00:00 2001 From: Furkan Senharputlu Date: Wed, 29 Jan 2020 18:36:52 +0300 Subject: [PATCH] Make universal options functions public (#1250) * Make universal options functions public --- universal.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/universal.go b/universal.go index 62fd0fd0..21c4d07a 100644 --- a/universal.go +++ b/universal.go @@ -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"} } @@ -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"} } @@ -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] @@ -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()) }