Skip to content

Commit

Permalink
Remove deprecated Ring options
Browse files Browse the repository at this point in the history
  • Loading branch information
vmihailenco committed May 19, 2020
1 parent 2b060bb commit 558263e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 48 deletions.
2 changes: 1 addition & 1 deletion example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
28 changes: 4 additions & 24 deletions ring.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
}
if opt.OnNewShard != nil {
opt.OnNewShard(shard)
return opt.NewClient(name, clopt)
}
return shard
return NewClient(clopt)
}

func (c *Ring) Context() context.Context {
Expand Down
23 changes: 0 additions & 23 deletions ring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 558263e

Please sign in to comment.