mirror of
https://github.com/redis/go-redis.git
synced 2025-07-28 06:42:00 +03:00
cluster: cleanup tests
This commit is contained in:
@ -1,9 +1,11 @@
|
||||
package redis
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/go-redis/redis/internal/hashtag"
|
||||
"github.com/go-redis/redis/internal/pool"
|
||||
)
|
||||
|
||||
@ -19,6 +21,14 @@ func (c *PubSub) ReceiveMessageTimeout(timeout time.Duration) (*Message, error)
|
||||
return c.receiveMessage(timeout)
|
||||
}
|
||||
|
||||
func (c *ClusterClient) GetState() (*clusterState, error) {
|
||||
return c.state.Get()
|
||||
}
|
||||
|
||||
func (c *ClusterClient) LoadState() (*clusterState, error) {
|
||||
return c.loadState()
|
||||
}
|
||||
|
||||
func (c *ClusterClient) SlotAddrs(slot int) []string {
|
||||
state, err := c.state.Get()
|
||||
if err != nil {
|
||||
@ -32,15 +42,25 @@ func (c *ClusterClient) SlotAddrs(slot int) []string {
|
||||
return addrs
|
||||
}
|
||||
|
||||
// SwapSlot swaps a slot's master/slave address for testing MOVED redirects.
|
||||
func (c *ClusterClient) SwapSlotNodes(slot int) {
|
||||
state, err := c.state.Get()
|
||||
func (c *ClusterClient) Nodes(key string) ([]*clusterNode, error) {
|
||||
state, err := c.state.Reload()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
slot := hashtag.Slot(key)
|
||||
nodes := state.slots[slot]
|
||||
if len(nodes) == 2 {
|
||||
nodes[0], nodes[1] = nodes[1], nodes[0]
|
||||
if len(nodes) != 2 {
|
||||
return nil, fmt.Errorf("slot=%d does not have enough nodes: %v", slot, nodes)
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (c *ClusterClient) SwapNodes(key string) error {
|
||||
nodes, err := c.Nodes(key)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
nodes[0], nodes[1] = nodes[1], nodes[0]
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user