forked from mirror/redis
Remove deprecated Ring options
This commit is contained in:
parent
2b060bb99d
commit
558263e5eb
|
@ -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 {
|
||||
|
|
28
ring.go
28
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 {
|
||||
|
|
23
ring_test.go
23
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()
|
||||
|
|
Loading…
Reference in New Issue