Remove deprecated Ring options

This commit is contained in:
Vladimir Mihailenco 2020-04-19 15:40:07 +03:00
parent 2b060bb99d
commit 558263e5eb
3 changed files with 5 additions and 48 deletions

View File

@ -154,7 +154,7 @@ func ExampleClient() {
} }
func ExampleConn() { func ExampleConn() {
conn := rdb.Conn() conn := rdb.Conn(context.Background())
err := conn.ClientSetName(ctx, "foobar").Err() err := conn.ClientSetName(ctx, "foobar").Err()
if err != nil { if err != nil {

26
ring.go
View File

@ -27,10 +27,6 @@ type RingOptions struct {
// Map of name => host:port addresses of ring shards. // Map of name => host:port addresses of ring shards.
Addrs map[string]string 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. // Frequency of PING commands sent to check shards availability.
// Shard is considered down after 3 subsequent failed checks. // Shard is considered down after 3 subsequent failed checks.
HeartbeatFrequency time.Duration HeartbeatFrequency time.Duration
@ -59,9 +55,6 @@ type RingOptions struct {
// NewClient creates a shard client with provided name and options. // NewClient creates a shard client with provided name and options.
NewClient func(name string, opt *Options) *Client 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. // Following options are copied from Options struct.
OnConnect func(*Conn) error OnConnect func(*Conn) error
@ -113,7 +106,6 @@ func (opt *RingOptions) clientOptions(shard string) *Options {
OnConnect: opt.OnConnect, OnConnect: opt.OnConnect,
DB: opt.DB, DB: opt.DB,
Password: opt.getPassword(shard),
DialTimeout: opt.DialTimeout, DialTimeout: opt.DialTimeout,
ReadTimeout: opt.ReadTimeout, 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 { type ringShard struct {
@ -395,16 +380,11 @@ func NewRing(opt *RingOptions) *Ring {
func newRingShard(opt *RingOptions, name, addr string) *Client { func newRingShard(opt *RingOptions, name, addr string) *Client {
clopt := opt.clientOptions(name) clopt := opt.clientOptions(name)
clopt.Addr = addr clopt.Addr = addr
var shard *Client
if opt.NewClient != nil { if opt.NewClient != nil {
shard = opt.NewClient(name, clopt) return opt.NewClient(name, clopt)
} else {
shard = NewClient(clopt)
} }
if opt.OnNewShard != nil { return NewClient(clopt)
opt.OnNewShard(shard)
}
return shard
} }
func (c *Ring) Context() context.Context { func (c *Ring) Context() context.Context {

View File

@ -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() { Describe("new client callback", func() {
It("can be initialized with a new client callback", func() { It("can be initialized with a new client callback", func() {
opts := redisRingOptions() opts := redisRingOptions()