From 558263e5ebfca4ccde89575904e5f7f466c699ed Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Sun, 19 Apr 2020 15:40:07 +0300 Subject: [PATCH] Remove deprecated Ring options --- example_test.go | 2 +- ring.go | 28 ++++------------------------ ring_test.go | 23 ----------------------- 3 files changed, 5 insertions(+), 48 deletions(-) diff --git a/example_test.go b/example_test.go index 1e72bc4d..32154a45 100644 --- a/example_test.go +++ b/example_test.go @@ -154,7 +154,7 @@ func ExampleClient() { } func ExampleConn() { - conn := rdb.Conn() + conn := rdb.Conn(context.Background()) err := conn.ClientSetName(ctx, "foobar").Err() if err != nil { diff --git a/ring.go b/ring.go index 5833eff7..2a00e532 100644 --- a/ring.go +++ b/ring.go @@ -27,10 +27,6 @@ type RingOptions struct { // Map of name => host:port addresses of ring shards. Addrs map[string]string - // Map of name => password of ring shards, to allow different shards to have - // different passwords. It will be ignored if the Password field is set. - Passwords map[string]string - // Frequency of PING commands sent to check shards availability. // Shard is considered down after 3 subsequent failed checks. HeartbeatFrequency time.Duration @@ -59,9 +55,6 @@ type RingOptions struct { // NewClient creates a shard client with provided name and options. NewClient func(name string, opt *Options) *Client - // Optional hook that is called when a new shard is created. - OnNewShard func(*Client) - // Following options are copied from Options struct. OnConnect func(*Conn) error @@ -112,8 +105,7 @@ func (opt *RingOptions) clientOptions(shard string) *Options { return &Options{ OnConnect: opt.OnConnect, - DB: opt.DB, - Password: opt.getPassword(shard), + DB: opt.DB, DialTimeout: opt.DialTimeout, ReadTimeout: opt.ReadTimeout, @@ -128,13 +120,6 @@ func (opt *RingOptions) clientOptions(shard string) *Options { } } -func (opt *RingOptions) getPassword(shard string) string { - if opt.Password == "" { - return opt.Passwords[shard] - } - return opt.Password -} - //------------------------------------------------------------------------------ type ringShard struct { @@ -395,16 +380,11 @@ func NewRing(opt *RingOptions) *Ring { func newRingShard(opt *RingOptions, name, addr string) *Client { clopt := opt.clientOptions(name) clopt.Addr = addr - var shard *Client + if opt.NewClient != nil { - shard = opt.NewClient(name, clopt) - } else { - shard = NewClient(clopt) + return opt.NewClient(name, clopt) } - if opt.OnNewShard != nil { - opt.OnNewShard(shard) - } - return shard + return NewClient(clopt) } func (c *Ring) Context() context.Context { diff --git a/ring_test.go b/ring_test.go index 2e5a54cb..4e4e4a95 100644 --- a/ring_test.go +++ b/ring_test.go @@ -173,29 +173,6 @@ var _ = Describe("Redis Ring", func() { }) }) - Describe("shard passwords", func() { - It("can be initialized with a single password, used for all shards", func() { - opts := redisRingOptions() - opts.Password = "password" - ring = redis.NewRing(opts) - - err := ring.Ping(ctx).Err() - Expect(err).To(MatchError("ERR Client sent AUTH, but no password is set")) - }) - - It("can be initialized with a passwords map, one for each shard", func() { - opts := redisRingOptions() - opts.Passwords = map[string]string{ - "ringShardOne": "password1", - "ringShardTwo": "password2", - } - ring = redis.NewRing(opts) - - err := ring.Ping().Err() - Expect(err).To(MatchError("ERR Client sent AUTH, but no password is set")) - }) - }) - Describe("new client callback", func() { It("can be initialized with a new client callback", func() { opts := redisRingOptions()