2013-11-07 18:20:15 +04:00
|
|
|
package redis
|
|
|
|
|
2016-03-17 19:00:47 +03:00
|
|
|
import (
|
2017-04-17 15:43:58 +03:00
|
|
|
"net"
|
2016-03-17 19:00:47 +03:00
|
|
|
"time"
|
|
|
|
|
2017-02-18 17:42:34 +03:00
|
|
|
"github.com/go-redis/redis/internal/pool"
|
2016-03-17 19:00:47 +03:00
|
|
|
)
|
2015-05-10 15:33:04 +03:00
|
|
|
|
2016-03-12 11:52:13 +03:00
|
|
|
func (c *baseClient) Pool() pool.Pooler {
|
2013-11-07 18:20:15 +04:00
|
|
|
return c.connPool
|
|
|
|
}
|
2015-03-23 11:23:33 +03:00
|
|
|
|
2017-04-17 15:43:58 +03:00
|
|
|
func (c *PubSub) SetNetConn(netConn net.Conn) {
|
|
|
|
c.cn = pool.NewConn(netConn)
|
2016-03-01 13:31:06 +03:00
|
|
|
}
|
2016-03-17 19:00:47 +03:00
|
|
|
|
2016-04-09 14:52:01 +03:00
|
|
|
func (c *PubSub) ReceiveMessageTimeout(timeout time.Duration) (*Message, error) {
|
|
|
|
return c.receiveMessage(timeout)
|
2016-03-17 19:00:47 +03:00
|
|
|
}
|
2016-11-08 12:46:44 +03:00
|
|
|
|
|
|
|
func (c *ClusterClient) SlotAddrs(slot int) []string {
|
2017-08-31 15:22:47 +03:00
|
|
|
state, err := c.state()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2016-11-08 12:46:44 +03:00
|
|
|
var addrs []string
|
2017-08-31 15:22:47 +03:00
|
|
|
for _, n := range state.slotNodes(slot) {
|
2016-11-08 12:46:44 +03:00
|
|
|
addrs = append(addrs, n.Client.getAddr())
|
|
|
|
}
|
|
|
|
return addrs
|
|
|
|
}
|
|
|
|
|
|
|
|
// SwapSlot swaps a slot's master/slave address for testing MOVED redirects.
|
2017-07-09 13:10:07 +03:00
|
|
|
func (c *ClusterClient) SwapSlotNodes(slot int) {
|
2017-08-31 15:22:47 +03:00
|
|
|
state, err := c.state()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
nodes := state.slots[slot]
|
2017-07-09 13:10:07 +03:00
|
|
|
if len(nodes) == 2 {
|
|
|
|
nodes[0], nodes[1] = nodes[1], nodes[0]
|
|
|
|
}
|
2016-11-08 12:46:44 +03:00
|
|
|
}
|