mediocregopher / radix.v2

Redis client for Go
http://godoc.org/github.com/mediocregopher/radix.v2
MIT License
433 stars 92 forks source link

Opts in RedisCluster just support one addr, more than one addr is better #36

Closed andyli029 closed 8 years ago

andyli029 commented 8 years ago

type Opts struct {

// Required. The address of a single node in the cluster
Addr string

..... }

    opts := cluster.Opts{Addr:"10.150.110.171:6000", Dialer: df}
    conn, err := cluster.NewWithOpts(opts)
    ......
mediocregopher commented 8 years ago

Can you explain why more than one address would be better?

andyli029 commented 8 years ago

@mediocregopher when the address is failed,you can visit the next addr to avoid single point of failure. in other RedisCluster SDKS,in general multiple addresses are used, so the RedisCluster class will iterate over the provided nodes until it can attain a connection to the cluster

mediocregopher commented 8 years ago

It's not a bad idea, unfortunately there's not a very clean way to introduce it to the api right now, but I'll keep it in mind for the next iteration. In the meantime you could write a simple loop that does effectively the same thing:

var c *cluster.Cluster
var lastErr error
opts := cluster.Opts{ ... }
for _, addr := range addrs {
    opts.Addr = addr
    if c, lastErr = cluster.NewWithOpts(opts); lastErr == nil {
        break
    }
}
if lastErr != nil {
    panic(lastErr)
}
andyli029 commented 8 years ago

@mediocregopher Thanks a lot.