mirror of https://github.com/go-redis/redis.git
Remove Addr field from clusterNode
This commit is contained in:
parent
5a272d03b9
commit
84ae986659
|
@ -13,7 +13,6 @@ import (
|
|||
)
|
||||
|
||||
type clusterNode struct {
|
||||
Addr string
|
||||
Client *Client
|
||||
Latency time.Duration
|
||||
}
|
||||
|
@ -152,7 +151,7 @@ func (c *ClusterClient) nodeByAddr(addr string) (*clusterNode, error) {
|
|||
if !ok {
|
||||
node = c.newNode(addr)
|
||||
c.nodes[addr] = node
|
||||
c.addrs = append(c.addrs, node.Addr)
|
||||
c.addrs = append(c.addrs, addr)
|
||||
}
|
||||
|
||||
return node, nil
|
||||
|
@ -162,7 +161,6 @@ func (c *ClusterClient) newNode(addr string) *clusterNode {
|
|||
opt := c.opt.clientOptions()
|
||||
opt.Addr = addr
|
||||
return &clusterNode{
|
||||
Addr: addr,
|
||||
Client: NewClient(opt),
|
||||
}
|
||||
}
|
||||
|
@ -313,7 +311,7 @@ func (c *ClusterClient) Process(cmd Cmder) error {
|
|||
moved, ask, addr = errors.IsMoved(err)
|
||||
if moved || ask {
|
||||
master, _ := c.slotMasterNode(slot)
|
||||
if moved && (master == nil || master.Addr != addr) {
|
||||
if moved && (master == nil || master.Client.getAddr() != addr) {
|
||||
c.lazyReloadSlots()
|
||||
}
|
||||
|
||||
|
@ -425,7 +423,7 @@ func (c *ClusterClient) reloadSlots() {
|
|||
|
||||
slots, err := node.Client.ClusterSlots().Result()
|
||||
if err != nil {
|
||||
internal.Logf("ClusterSlots on addr=%q failed: %s", node.Addr, err)
|
||||
internal.Logf("ClusterSlots on addr=%q failed: %s", node.Client.getAddr(), err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
func (c *ClusterClient) SlotAddrs(slot int) []string {
|
||||
var addrs []string
|
||||
for _, n := range c.slotNodes(slot) {
|
||||
addrs = append(addrs, n.Addr)
|
||||
addrs = append(addrs, n.Client.getAddr())
|
||||
}
|
||||
return addrs
|
||||
}
|
||||
|
@ -51,22 +51,22 @@ var _ = Describe("ClusterClient", func() {
|
|||
|
||||
It("should update slots cache", func() {
|
||||
populate()
|
||||
Expect(subject.slots[0][0].Addr).To(Equal("127.0.0.1:7000"))
|
||||
Expect(subject.slots[0][1].Addr).To(Equal("127.0.0.1:7004"))
|
||||
Expect(subject.slots[4095][0].Addr).To(Equal("127.0.0.1:7000"))
|
||||
Expect(subject.slots[4095][1].Addr).To(Equal("127.0.0.1:7004"))
|
||||
Expect(subject.slots[4096][0].Addr).To(Equal("127.0.0.1:7001"))
|
||||
Expect(subject.slots[4096][1].Addr).To(Equal("127.0.0.1:7005"))
|
||||
Expect(subject.slots[8191][0].Addr).To(Equal("127.0.0.1:7001"))
|
||||
Expect(subject.slots[8191][1].Addr).To(Equal("127.0.0.1:7005"))
|
||||
Expect(subject.slots[8192][0].Addr).To(Equal("127.0.0.1:7002"))
|
||||
Expect(subject.slots[8192][1].Addr).To(Equal("127.0.0.1:7006"))
|
||||
Expect(subject.slots[12287][0].Addr).To(Equal("127.0.0.1:7002"))
|
||||
Expect(subject.slots[12287][1].Addr).To(Equal("127.0.0.1:7006"))
|
||||
Expect(subject.slots[12288][0].Addr).To(Equal("127.0.0.1:7003"))
|
||||
Expect(subject.slots[12288][1].Addr).To(Equal("127.0.0.1:7007"))
|
||||
Expect(subject.slots[16383][0].Addr).To(Equal("127.0.0.1:7003"))
|
||||
Expect(subject.slots[16383][1].Addr).To(Equal("127.0.0.1:7007"))
|
||||
Expect(subject.slots[0][0].Client.getAddr()).To(Equal("127.0.0.1:7000"))
|
||||
Expect(subject.slots[0][1].Client.getAddr()).To(Equal("127.0.0.1:7004"))
|
||||
Expect(subject.slots[4095][0].Client.getAddr()).To(Equal("127.0.0.1:7000"))
|
||||
Expect(subject.slots[4095][1].Client.getAddr()).To(Equal("127.0.0.1:7004"))
|
||||
Expect(subject.slots[4096][0].Client.getAddr()).To(Equal("127.0.0.1:7001"))
|
||||
Expect(subject.slots[4096][1].Client.getAddr()).To(Equal("127.0.0.1:7005"))
|
||||
Expect(subject.slots[8191][0].Client.getAddr()).To(Equal("127.0.0.1:7001"))
|
||||
Expect(subject.slots[8191][1].Client.getAddr()).To(Equal("127.0.0.1:7005"))
|
||||
Expect(subject.slots[8192][0].Client.getAddr()).To(Equal("127.0.0.1:7002"))
|
||||
Expect(subject.slots[8192][1].Client.getAddr()).To(Equal("127.0.0.1:7006"))
|
||||
Expect(subject.slots[12287][0].Client.getAddr()).To(Equal("127.0.0.1:7002"))
|
||||
Expect(subject.slots[12287][1].Client.getAddr()).To(Equal("127.0.0.1:7006"))
|
||||
Expect(subject.slots[12288][0].Client.getAddr()).To(Equal("127.0.0.1:7003"))
|
||||
Expect(subject.slots[12288][1].Client.getAddr()).To(Equal("127.0.0.1:7007"))
|
||||
Expect(subject.slots[16383][0].Client.getAddr()).To(Equal("127.0.0.1:7003"))
|
||||
Expect(subject.slots[16383][1].Client.getAddr()).To(Equal("127.0.0.1:7007"))
|
||||
Expect(subject.addrs).To(Equal([]string{
|
||||
"127.0.0.1:6379",
|
||||
"127.0.0.1:7003",
|
||||
|
|
6
redis.go
6
redis.go
|
@ -24,7 +24,7 @@ type baseClient struct {
|
|||
}
|
||||
|
||||
func (c *baseClient) String() string {
|
||||
return fmt.Sprintf("Redis<%s db:%d>", c.opt.Addr, c.opt.DB)
|
||||
return fmt.Sprintf("Redis<%s db:%d>", c.getAddr(), c.opt.DB)
|
||||
}
|
||||
|
||||
func (c *baseClient) conn() (*pool.Conn, bool, error) {
|
||||
|
@ -140,6 +140,10 @@ func (c *baseClient) Close() error {
|
|||
return retErr
|
||||
}
|
||||
|
||||
func (c *baseClient) getAddr() string {
|
||||
return c.opt.Addr
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Client is a Redis client representing a pool of zero or more
|
||||
|
|
Loading…
Reference in New Issue