From c0973178753e53d38cd338256f74cc7876844175 Mon Sep 17 00:00:00 2001 From: Stephanie Hingtgen Date: Fri, 22 Oct 2021 08:56:01 -0600 Subject: [PATCH] feat: add strings function --- cluster.go | 9 ++------- options.go | 20 +++++++++----------- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/cluster.go b/cluster.go index 3632ce9..e0ad4ba 100644 --- a/cluster.go +++ b/cluster.go @@ -233,19 +233,14 @@ func setupClusterQueryParams(u *url.URL, o *ClusterOptions) (*ClusterOptions, er } // addr can be specified as many times as needed - addr := q.string("addr") - for addr != "" { + addrs := q.strings("addr") + for _, addr := range addrs { h, p, err := net.SplitHostPort(addr) if err != nil || h == "" || p == "" { return nil, fmt.Errorf("redis: unable to parse addr param: %s", addr) } o.Addrs = append(o.Addrs, net.JoinHostPort(h, p)) - - addr = q.string("addr") - if q.err != nil { - return nil, q.err - } } // any parameters left? diff --git a/options.go b/options.go index faa58c4..7658a75 100644 --- a/options.go +++ b/options.go @@ -301,20 +301,18 @@ type queryOptions struct { } func (o *queryOptions) string(name string) string { - if len(o.q[name]) == 0 { + vs := o.q[name] + if len(vs) == 0 { return "" } - // get the first item from the array to return - // and remove it so it isn't processed again - param := o.q[name][0] - o.q[name] = o.q[name][1:] + delete(o.q, name) // enable detection of unknown parameters + return vs[len(vs)-1] +} - // remove the key to enable detection of unknown params - if len(o.q[name]) == 0 { - delete(o.q, name) - } - - return param +func (o *queryOptions) strings(name string) []string { + vs := o.q[name] + delete(o.q, name) + return vs } func (o *queryOptions) int(name string) int {