Documentation
¶
Index ¶
- Constants
- Variables
- func Contains(s []Slot, e Slot) bool
- func DecodeNodeStartTime(input *string, log logr.Logger) (time.Time, error)
- func DecodeSlotRange(str string) ([]Slot, *ImportingSlot, *MigratingSlot, error)
- func IsInconsistentError(err error) bool
- func IsNodeNotFoundedError(err error) bool
- func IsPartialError(err error) bool
- func LessByID(n1, n2 *ClusterNode) bool
- func MoreByID(n1, n2 *ClusterNode) bool
- type AdminConnections
- func (cnx *AdminConnections) Add(addr string) error
- func (cnx *AdminConnections) AddAll(addrs []string)
- func (cnx *AdminConnections) Close()
- func (cnx *AdminConnections) Get(addr string) (IClient, error)
- func (cnx *AdminConnections) GetAUTH() (string, bool)
- func (cnx *AdminConnections) GetAll() map[string]IClient
- func (cnx *AdminConnections) GetDifferentFrom(addr string) (IClient, error)
- func (cnx *AdminConnections) GetRandom() (IClient, error)
- func (cnx *AdminConnections) GetSelected(addrs []string) map[string]IClient
- func (cnx *AdminConnections) Reconnect(addr string) error
- func (cnx *AdminConnections) Remove(addr string)
- func (cnx *AdminConnections) ReplaceAll(addrs []string)
- func (cnx *AdminConnections) Reset()
- func (cnx *AdminConnections) Update(addr string) (IClient, error)
- func (cnx *AdminConnections) ValidatePipeResp(client IClient, addr, errMessage string) bool
- func (cnx *AdminConnections) ValidateResp(resp *redis.Resp, addr, errMessage string) error
- type AdminOptions
- type Client
- type Cluster
- type ClusterActionsInfo
- type ClusterAdmin
- func (a *ClusterAdmin) AddSlots(addr string, slots []Slot) error
- func (a *ClusterAdmin) AttachNodeToCluster(addr string) error
- func (a *ClusterAdmin) AttachSlaveToMaster(slave *ClusterNode, masterID string) error
- func (a *ClusterAdmin) Close()
- func (a *ClusterAdmin) ClusterManagerNodeIsEmpty() (bool, error)
- func (a *ClusterAdmin) Connections() IAdminConnections
- func (a *ClusterAdmin) DetachSlave(slave *ClusterNode) error
- func (a *ClusterAdmin) FlushAndReset(addr string, mode string) error
- func (a *ClusterAdmin) ForgetNode(id string) error
- func (a *ClusterAdmin) GetAllConfig(c IClient, addr string) (map[string]string, error)
- func (a *ClusterAdmin) GetClusterInfos() (*ClusterInfos, error)
- func (a *ClusterAdmin) GetHashMaxSlot() Slot
- func (a *ClusterAdmin) MigrateKeys(addr string, dest *ClusterNode, slots []Slot, batch int, timeout int, ...) (int, error)
- func (a *ClusterAdmin) MigrateKeysInSlot(addr string, dest *ClusterNode, slot Slot, batch int, timeout int, ...) (int, error)
- func (a *ClusterAdmin) SetConfigEpoch() error
- func (a *ClusterAdmin) SetSlot(addr, action string, slot Slot, nodeID string) error
- func (a *ClusterAdmin) SetSlots(addr, action string, slots []Slot, nodeID string) error
- type ClusterInfos
- type ClusterInfosError
- type ClusterNode
- func (n *ClusterNode) Balance() int
- func (n *ClusterNode) Clear()
- func (n *ClusterNode) GetRole() composev1alpha1.RedisClusterNodeRole
- func (n *ClusterNode) HasStatus(flag string) bool
- func (n *ClusterNode) IPPort() string
- func (n *ClusterNode) SetBalance(balance int)
- func (n *ClusterNode) SetFailureStatus(flags string)
- func (n *ClusterNode) SetLinkStatus(status string) error
- func (n *ClusterNode) SetReferentMaster(ref string)
- func (n *ClusterNode) SetRole(flags string) error
- func (n *ClusterNode) String() string
- func (n *ClusterNode) ToAPINode() composev1alpha1.RedisClusterNode
- func (n *ClusterNode) TotalSlots() int
- type ClusterNodes
- func (n ClusterNodes) CountByFunc(fn func(*ClusterNode) bool) (result int)
- func (n ClusterNodes) FilterByFunc(fn func(*ClusterNode) bool) ClusterNodes
- func (n ClusterNodes) GetNodeByID(id string) (*ClusterNode, error)
- func (n ClusterNodes) GetNodesByFunc(f FindNodeFunc) (ClusterNodes, error)
- func (n ClusterNodes) Len() int
- func (n ClusterNodes) Less(i, j int) bool
- func (n ClusterNodes) SortByFunc(less func(*ClusterNode, *ClusterNode) bool) ClusterNodes
- func (n ClusterNodes) SortNodes() ClusterNodes
- func (n ClusterNodes) String() string
- func (n ClusterNodes) Swap(i, j int)
- type ClusterStatus
- type ConfigSignature
- type Error
- type FindNodeFunc
- type IAdminConnections
- type IClient
- type IClusterAdmin
- type IReplicationAdmin
- type ImportingSlot
- type MigratingSlot
- type NodeInfos
- type ReplicationAdmin
- func (a *ReplicationAdmin) Close()
- func (a *ReplicationAdmin) Connections() IAdminConnections
- func (a *ReplicationAdmin) GetReplicationStatus() *ReplicationInfo
- func (a *ReplicationAdmin) ReplicaOfNoOne(addr string) error
- func (a *ReplicationAdmin) ReplicaOfSource(addr, sourceHost, sourcePort string) error
- type ReplicationInfo
- type ReplicationNode
- type ReplicationNodes
- type Slot
- type SlotRange
- type SlotSlice
Constants ¶
const ( // DefaultHashMaxSlots higher value of slot // as slots start at 0, total number of slots is defaultHashMaxSlots+1 DefaultHashMaxSlots = 16383 // ResetHard HARD mode for RESET command ResetHard = "HARD" // ResetSoft SOFT mode for RESET command ResetSoft = "SOFT" )
const ( // ClusterInfosUnset status of the cluster info: no data set ClusterInfosUnset = "Unset" // ClusterInfosPartial status of the cluster info: data is not complete (some nodes didn't respond) ClusterInfosPartial = "Partial" // ClusterInfosInconsistent status of the cluster info: nodesinfos is not consistent between nodes ClusterInfosInconsistent = "Inconsistent" // ClusterInfosConsistent status of the cluster info: nodeinfos is complete and consistent between nodes ClusterInfosConsistent = "Consistent" )
const ( // DefaultRedisPort define the default Redis Port DefaultRedisPort = "6379" // RedisMasterRole redis role master RedisMasterRole = "master" // RedisSlaveRole redis role slave RedisSlaveRole = "slave" // RedisSourceRole redis role source RedisSourceRole = "Source" // RedisReplicaRole redis role replica RedisReplicaRole = "Replica" // RedisLinkStateConnected redis connection status connected RedisLinkStateConnected = "connected" // RedisLinkStateDisconnected redis connection status disconnected RedisLinkStateDisconnected = "disconnected" // NodeStatusPFail ClusterNode is in PFAIL state. Not reachable for the node you are contacting, but still logically reachable NodeStatusPFail = "fail?" // NodeStatusFail ClusterNode is in FAIL state. It was not reachable for multiple nodes that promoted the PFAIL state to FAIL NodeStatusFail = "fail" // NodeStatusHandshake Untrusted node, we are handshaking. NodeStatusHandshake = "handshake" // NodeStatusNoAddr No address known for this node NodeStatusNoAddr = "noaddr" // NodeStatusNoFlags no flags at all NodeStatusNoFlags = "noflags" )
const (
// ErrNotFound cannot find a node to connect to
ErrNotFound = "unable to find a node to connect"
)
Variables ¶
var IsMasterWithNoSlot = func(n *ClusterNode) bool { if (n.GetRole() == composev1alpha1.RedisClusterNodeRoleSource) && (n.TotalSlots() == 0) { return true } return false }
IsMasterWithNoSlot anonymous function for searching Master ClusterNode with no slot
var IsMasterWithSlot = func(n *ClusterNode) bool { if (n.GetRole() == composev1alpha1.RedisClusterNodeRoleSource) && (n.TotalSlots() > 0) { return true } return false }
IsMasterWithSlot anonymous function for searching Master ClusterNode withslot
var IsSlave = func(n *ClusterNode) bool { return n.GetRole() == composev1alpha1.RedisClusterNodeRoleReplica }
IsSlave anonymous function for searching Slave ClusterNode
Functions ¶
func DecodeNodeStartTime ¶
DecodeNodeStartTime decode from the cmd output the Redis instance info. Second argument is the node on which we are connected to request info
func DecodeSlotRange ¶
func DecodeSlotRange(str string) ([]Slot, *ImportingSlot, *MigratingSlot, error)
DecodeSlotRange decode from a string a RangeSlot
each entry can have 4 representations: * single slot: ex: 42 * slot range: ex: 42-52 * migrating slot: ex: [42->-67ed2db8d677e59ec4a4cefb06858cf2a1a89fa1] * importing slot: ex: [42-<-67ed2db8d677e59ec4a4cefb06858cf2a1a89fa1]
func IsInconsistentError ¶
IsInconsistentError eturns true if the error is due to cluster inconsistencies
func IsNodeNotFoundedError ¶
IsNodeNotFoundedError returns true if the current error is a NodeNotFoundedError
func IsPartialError ¶
IsPartialError returns true if the error is due to partial data recovery
func LessByID ¶
func LessByID(n1, n2 *ClusterNode) bool
LessByID compare 2 ReplicationNodes with their ID
func MoreByID ¶
func MoreByID(n1, n2 *ClusterNode) bool
MoreByID compare 2 ReplicationNodes with their ID
Types ¶
type AdminConnections ¶
type AdminConnections struct {
// contains filtered or unexported fields
}
AdminConnections connection map for redis cluster currently the admin connection is not threadSafe since it is only use in the Events thread.
func (*AdminConnections) Add ¶
func (cnx *AdminConnections) Add(addr string) error
Add connect to the given address and register the client connection to the map
func (*AdminConnections) AddAll ¶
func (cnx *AdminConnections) AddAll(addrs []string)
AddAll connect to the given list of addresses and register them in the map fail silently
func (*AdminConnections) Close ¶
func (cnx *AdminConnections) Close()
Close used to close all possible resources instanciate by the Connections
func (*AdminConnections) Get ¶
func (cnx *AdminConnections) Get(addr string) (IClient, error)
Get returns a client connection for the given adress, connects if the connection is not in the map yet
func (*AdminConnections) GetAUTH ¶
func (cnx *AdminConnections) GetAUTH() (string, bool)
GetAUTH return password and true if connection password is set, else return false.
func (*AdminConnections) GetAll ¶
func (cnx *AdminConnections) GetAll() map[string]IClient
GetAll returns a map of all clients per address
func (*AdminConnections) GetDifferentFrom ¶
func (cnx *AdminConnections) GetDifferentFrom(addr string) (IClient, error)
GetDifferentFrom returns random a client connection different from given address
func (*AdminConnections) GetRandom ¶
func (cnx *AdminConnections) GetRandom() (IClient, error)
GetRandom returns a client connection to a random node of the client map
func (*AdminConnections) GetSelected ¶
func (cnx *AdminConnections) GetSelected(addrs []string) map[string]IClient
GetSelected returns a map of clients based on the input addresses
func (*AdminConnections) Reconnect ¶
func (cnx *AdminConnections) Reconnect(addr string) error
Reconnect force a reconnection on the given address is the adress is not part of the map, act like Add
func (*AdminConnections) Remove ¶
func (cnx *AdminConnections) Remove(addr string)
Remove disconnect and remove the client connection from the map
func (*AdminConnections) ReplaceAll ¶
func (cnx *AdminConnections) ReplaceAll(addrs []string)
ReplaceAll clear the pool and re-populate it with new connections fail silently
func (*AdminConnections) Reset ¶
func (cnx *AdminConnections) Reset()
Reset close all connections and clear the connection map
func (*AdminConnections) Update ¶
func (cnx *AdminConnections) Update(addr string) (IClient, error)
Update returns a client connection for the given adress, connects if the connection is not in the map yet
func (*AdminConnections) ValidatePipeResp ¶
func (cnx *AdminConnections) ValidatePipeResp(client IClient, addr, errMessage string) bool
ValidatePipeResp wait for all answers in the pipe and validate the response in case of network issue clear the pipe and return in case of error, return false
func (*AdminConnections) ValidateResp ¶
func (cnx *AdminConnections) ValidateResp(resp *redis.Resp, addr, errMessage string) error
ValidateResp check the redis resp, eventually reconnect on connection error in case of error, customize the error, log it and return it
type AdminOptions ¶
AdminOptions optional options for redis admin
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client structure representing a client connection to redis
func (*Client) PipeAppend ¶
PipeAppend adds the given call to the pipeline queue.
type Cluster ¶
type Cluster struct { Name string Namespace string Nodes map[string]*ClusterNode Status ClusterStatus ActionsInfo ClusterActionsInfo }
Cluster represents a Redis Cluster
func NewCluster ¶
NewCluster builds and returns new Cluster instance
func (*Cluster) AddNode ¶
func (c *Cluster) AddNode(node *ClusterNode)
AddNode used to add new ClusterNode in the cluster if node with the same ID is already present in the cluster the previous ClusterNode is replaced
func (*Cluster) GetNodeByFunc ¶
func (c *Cluster) GetNodeByFunc(f FindNodeFunc) (*ClusterNode, error)
GetNodeByFunc returns first node found by the FindNodeFunc
func (*Cluster) GetNodeByID ¶
func (c *Cluster) GetNodeByID(id string) (*ClusterNode, error)
GetNodeByID returns a Cluster ClusterNode by its ID if not present in the cluster return an error
func (*Cluster) GetNodeByIP ¶
func (c *Cluster) GetNodeByIP(ip string) (*ClusterNode, error)
GetNodeByIP returns a Cluster ClusterNode by its ID if not present in the cluster return an error
type ClusterActionsInfo ¶
type ClusterActionsInfo struct {
NbslotsToMigrate int32
}
ClusterActionsInfo use to store information about current action on the Cluster
type ClusterAdmin ¶
type ClusterAdmin struct {
// contains filtered or unexported fields
}
ClusterAdmin wraps redis cluster admin logic
func (*ClusterAdmin) AddSlots ¶
func (a *ClusterAdmin) AddSlots(addr string, slots []Slot) error
AddSlots use to ADDSLOT commands on several slots
func (*ClusterAdmin) AttachNodeToCluster ¶
func (a *ClusterAdmin) AttachNodeToCluster(addr string) error
AttachNodeToCluster command use to connect a ClusterNode to the cluster
func (*ClusterAdmin) AttachSlaveToMaster ¶
func (a *ClusterAdmin) AttachSlaveToMaster(slave *ClusterNode, masterID string) error
AttachSlaveToMaster attach a slave to a master node
func (*ClusterAdmin) Close ¶
func (a *ClusterAdmin) Close()
Close used to close all possible resources instanciate by the ClusterAdmin
func (*ClusterAdmin) ClusterManagerNodeIsEmpty ¶
func (a *ClusterAdmin) ClusterManagerNodeIsEmpty() (bool, error)
ClusterManagerNodeIsEmpty Checks whether the node is empty. ClusterNode is considered not-empty if it has some key or if it already knows other nodes
func (*ClusterAdmin) Connections ¶
func (a *ClusterAdmin) Connections() IAdminConnections
Connections returns the connection map of all clients
func (*ClusterAdmin) DetachSlave ¶
func (a *ClusterAdmin) DetachSlave(slave *ClusterNode) error
DetachSlave use to detach a slave to a master
func (*ClusterAdmin) FlushAndReset ¶
func (a *ClusterAdmin) FlushAndReset(addr string, mode string) error
FlushAndReset flush the cluster and reset the cluster configuration of the node. Commands are piped, to ensure no items arrived between flush and reset
func (*ClusterAdmin) ForgetNode ¶
func (a *ClusterAdmin) ForgetNode(id string) error
ForgetNode used to force other redis cluster node to forget a specific node
func (*ClusterAdmin) GetAllConfig ¶
GetAllConfig get redis config by CONFIG GET *
func (*ClusterAdmin) GetClusterInfos ¶
func (a *ClusterAdmin) GetClusterInfos() (*ClusterInfos, error)
GetClusterInfos return the ReplicationNodes infos for all nodes
func (*ClusterAdmin) GetHashMaxSlot ¶
func (a *ClusterAdmin) GetHashMaxSlot() Slot
GetHashMaxSlot get the max slot value
func (*ClusterAdmin) MigrateKeys ¶
func (a *ClusterAdmin) MigrateKeys(addr string, dest *ClusterNode, slots []Slot, batch int, timeout int, replace bool) (int, error)
MigrateKeys use to migrate keys from slots to other slots. if replace is true, replace key on busy error timeout is in milliseconds
func (*ClusterAdmin) MigrateKeysInSlot ¶
func (a *ClusterAdmin) MigrateKeysInSlot(addr string, dest *ClusterNode, slot Slot, batch int, timeout int, replace bool) (int, error)
MigrateKeysInSlot use to migrate keys from slot to other slot. if replace is true, replace key on busy error timeout is in milliseconds
func (*ClusterAdmin) SetConfigEpoch ¶
func (a *ClusterAdmin) SetConfigEpoch() error
type ClusterInfos ¶
ClusterInfos represents the node infos for all nodes of the cluster
func NewClusterInfos ¶
func NewClusterInfos() *ClusterInfos
NewClusterInfos returns an instance of ClusterInfos
func (*ClusterInfos) ComputeStatus ¶
func (c *ClusterInfos) ComputeStatus(log logr.Logger) bool
ComputeStatus check the ClusterInfos status based on the current data the status ClusterInfosPartial is set while building the clusterinfos if already set, do nothing returns true if contistent or if another error
func (*ClusterInfos) GetNodes ¶
func (c *ClusterInfos) GetNodes() ClusterNodes
GetNodes returns a nodeSlice view of the cluster the slice if formed from how each node see itself you should check the Status before doing it, to wait for a consistent view
type ClusterInfosError ¶
type ClusterInfosError struct {
// contains filtered or unexported fields
}
ClusterInfosError error type for redis cluster infos access
func NewClusterInfosError ¶
func NewClusterInfosError() ClusterInfosError
NewClusterInfosError returns an instance of cluster infos error
func (ClusterInfosError) Inconsistent ¶
func (e ClusterInfosError) Inconsistent() bool
Inconsistent true if the nodes do not agree with each other
func (ClusterInfosError) Partial ¶
func (e ClusterInfosError) Partial() bool
Partial true if the some nodes of the cluster didn't answer
type ClusterNode ¶
type ClusterNode struct { ID string IP string Port string Role string LinkState string MasterReferent string FailStatus []string PingSent int64 PongRecv int64 ConfigEpoch int64 Slots []Slot MigratingSlots map[Slot]string ImportingSlots map[Slot]string ServerStartTime time.Time NodeName string ShardName string // contains filtered or unexported fields }
ClusterNode Represent a Redis ClusterNode
func NewClusterNode ¶
func NewClusterNode(name, id, ip string) *ClusterNode
NewClusterNode builds and returns new ClusterNode instance
func NewDefaultClusterNode ¶
func NewDefaultClusterNode() *ClusterNode
NewDefaultClusterNode builds and returns new default cluster node instance
func (*ClusterNode) Balance ¶
func (n *ClusterNode) Balance() int
func (*ClusterNode) Clear ¶
func (n *ClusterNode) Clear()
Clear used to clear possible ressources attach to the current ClusterNode
func (*ClusterNode) GetRole ¶
func (n *ClusterNode) GetRole() composev1alpha1.RedisClusterNodeRole
GetRole return the Redis Cluster ClusterNode GetRole
func (*ClusterNode) HasStatus ¶
func (n *ClusterNode) HasStatus(flag string) bool
HasStatus returns true if the node has the provided fail status flag
func (*ClusterNode) IPPort ¶
func (n *ClusterNode) IPPort() string
IPPort returns join Ip Port string
func (*ClusterNode) SetBalance ¶
func (n *ClusterNode) SetBalance(balance int)
func (*ClusterNode) SetFailureStatus ¶
func (n *ClusterNode) SetFailureStatus(flags string)
SetFailureStatus set from inputs flags the possible failure status
func (*ClusterNode) SetLinkStatus ¶
func (n *ClusterNode) SetLinkStatus(status string) error
SetLinkStatus set the ClusterNode link status
func (*ClusterNode) SetReferentMaster ¶
func (n *ClusterNode) SetReferentMaster(ref string)
SetReferentMaster set the redis node parent referent
func (*ClusterNode) SetRole ¶
func (n *ClusterNode) SetRole(flags string) error
SetRole from a flags string list set the ClusterNode's role
func (*ClusterNode) String ¶
func (n *ClusterNode) String() string
String representation of an Instance
func (*ClusterNode) ToAPINode ¶
func (n *ClusterNode) ToAPINode() composev1alpha1.RedisClusterNode
ToAPINode used to convert the current ClusterNode to an API redisv1alpha1.RedisClusterNode
func (*ClusterNode) TotalSlots ¶
func (n *ClusterNode) TotalSlots() int
TotalSlots return the total number of slot
type ClusterNodes ¶
type ClusterNodes []*ClusterNode
ClusterNodes represent a ClusterNode slice
func (ClusterNodes) CountByFunc ¶
func (n ClusterNodes) CountByFunc(fn func(*ClusterNode) bool) (result int)
CountByFunc gives the number elements of NodeSlice that return true for the passed func.
func (ClusterNodes) FilterByFunc ¶
func (n ClusterNodes) FilterByFunc(fn func(*ClusterNode) bool) ClusterNodes
FilterByFunc remove a node from a slice by node ID and returns the slice. If not found, fail silently. Value must be unique
func (ClusterNodes) GetNodeByID ¶
func (n ClusterNodes) GetNodeByID(id string) (*ClusterNode, error)
GetNodeByID returns a Redis ClusterNode by its ID if not present in the ReplicationNodes slice return an error
func (ClusterNodes) GetNodesByFunc ¶
func (n ClusterNodes) GetNodesByFunc(f FindNodeFunc) (ClusterNodes, error)
GetNodesByFunc returns first node found by the FindNodeFunc
func (ClusterNodes) Len ¶
func (n ClusterNodes) Len() int
Len is the number of elements in the collection.
func (ClusterNodes) Less ¶
func (n ClusterNodes) Less(i, j int) bool
Less few reports whether the element with index i should sort before the element with index j.
func (ClusterNodes) SortByFunc ¶
func (n ClusterNodes) SortByFunc(less func(*ClusterNode, *ClusterNode) bool) ClusterNodes
SortByFunc returns a new ordered NodeSlice, determined by a func defining ‘less’.
func (ClusterNodes) SortNodes ¶
func (n ClusterNodes) SortNodes() ClusterNodes
SortNodes sort ReplicationNodes and return the sorted ReplicationNodes
func (ClusterNodes) String ¶
func (n ClusterNodes) String() string
func (ClusterNodes) Swap ¶
func (n ClusterNodes) Swap(i, j int)
Swap swaps the elements with indexes i and j.
type ClusterStatus ¶
type ClusterStatus string
ClusterStatus Redis Cluster status
const ( // ClusterStatusOK ClusterStatus OK ClusterStatusOK ClusterStatus = "Healthy" // ClusterStatusKO ClusterStatus KO ClusterStatusKO ClusterStatus = "Failed" )
type ConfigSignature ¶
ConfigSignature Represents the slots of each node
func (ConfigSignature) String ¶
func (c ConfigSignature) String() string
String representation of a ConfigSignaure
type FindNodeFunc ¶
type FindNodeFunc func(node *ClusterNode) bool
FindNodeFunc function for finding a ClusterNode it is use as input for GetNodeByFunc and GetNodesByFunc
type IAdminConnections ¶
type IAdminConnections interface { // Add connect to the given address and // register the client connection to the pool Add(addr string) error // Remove disconnect and remove the client connection from the map Remove(addr string) // Get returns a client connection for the given address, // connects if the connection is not in the map yet Get(addr string) (IClient, error) // GetRandom returns a client connection to a random node of the client map GetRandom() (IClient, error) // GetDifferentFrom returns a random client connection different from given address GetDifferentFrom(addr string) (IClient, error) // GetAll returns a map of all clients per address GetAll() map[string]IClient //GetSelected returns a map of clients based on the input addresses GetSelected(addrs []string) map[string]IClient // Reconnect force a reconnection on the given address // if the adress is not part of the map, act like Add Reconnect(addr string) error // AddAll connect to the given list of addresses and // register them in the map // fail silently AddAll(addrs []string) // ReplaceAll clear the map and re-populate it with new connections // fail silently ReplaceAll(addrs []string) // ValidateResp check the redis resp, eventually reconnect on connection error // in case of error, customize the error, log it and return it ValidateResp(resp *redis.Resp, addr, errMessage string) error // ValidatePipeResp wait for all answers in the pipe and validate the response // in case of network issue clear the pipe and return // in case of error return false ValidatePipeResp(c IClient, addr, errMessage string) bool // Reset close all connections and clear the connection map Reset() // GetAUTH return password and true if connection password is set, else return false. GetAUTH() (string, bool) }
IAdminConnections interface representing the map of admin connections to redis cluster nodes
func NewAdminConnections ¶
func NewAdminConnections(addrs []string, options *AdminOptions, log logr.Logger) IAdminConnections
NewAdminConnections returns and instance of AdminConnectionsInterface
type IClient ¶
type IClient interface { // Close closes the connection. Close() error // Cmd calls the given Redis command. Cmd(cmd string, args ...interface{}) *redis.Resp // PipeAppend adds the given call to the pipeline queue. // Use PipeResp() to read the response. PipeAppend(cmd string, args ...interface{}) // PipeResp returns the reply for the next request in the pipeline queue. Err // with ErrPipelineEmpty is returned if the pipeline queue is empty. PipeResp() *redis.Resp // PipeClear clears the contents of the current pipeline queue, both commands // queued by PipeAppend which have yet to be sent and responses which have yet // to be retrieved through PipeResp. The first returned int will be the number // of pending commands dropped, the second will be the number of pending // responses dropped PipeClear() (int, int) }
IClient redis client interface
type IClusterAdmin ¶
type IClusterAdmin interface { // Connections returns the connection map of all clients Connections() IAdminConnections // Close the admin connections Close() // GetClusterInfos get node infos for all nodes GetClusterInfos() (*ClusterInfos, error) // ClusterManagerNodeIsEmpty Checks whether the node is empty. ClusterNode is considered not-empty if it has // some key or if it already knows other nodes ClusterManagerNodeIsEmpty() (bool, error) // SetConfigEpoch Assign a different config epoch to each node SetConfigEpoch() error // GetAllConfig get redis config by CONFIG GET * GetAllConfig(c IClient, addr string) (map[string]string, error) // AttachNodeToCluster command use to connect a ClusterNode to the cluster // the connection will be done on a random node part of the connection pool AttachNodeToCluster(addr string) error // AttachSlaveToMaster attach a slave to a master node AttachSlaveToMaster(slave *ClusterNode, masterID string) error // DetachSlave dettach a slave to its master DetachSlave(slave *ClusterNode) error // ForgetNode execute the Redis command to force the cluster to forget the ClusterNode ForgetNode(id string) error // SetSlots exec the redis command to set slots in a pipeline, provide // and empty nodeID if the set slots commands doesn't take a nodeID in parameter SetSlots(addr string, action string, slots []Slot, nodeID string) error // AddSlots exec the redis command to add slots in a pipeline AddSlots(addr string, slots []Slot) error // SetSlot use to set SETSLOT command on a slot SetSlot(addr, action string, slot Slot, nodeID string) error // MigrateKeys from addr to destination node. returns number of slot migrated. If replace is true, replace key on busy error MigrateKeys(addr string, dest *ClusterNode, slots []Slot, batch, timeout int, replace bool) (int, error) // MigrateKeysInSlot use to migrate keys from slot to other slot. if replace is true, replace key on busy error // timeout is in milliseconds MigrateKeysInSlot(addr string, dest *ClusterNode, slot Slot, batch int, timeout int, replace bool) (int, error) // GetHashMaxSlot get the max slot value GetHashMaxSlot() Slot }
IClusterAdmin redis cluster admin interface
func NewClusterAdmin ¶
func NewClusterAdmin(addrs []string, options *AdminOptions, log logr.Logger) IClusterAdmin
NewClusterAdmin returns new AdminInterface instance at the same time it connects to all Redis ReplicationNodes thanks to the addrs list
type IReplicationAdmin ¶
type IReplicationAdmin interface { // Connections returns the connection map of all clients Connections() IAdminConnections // Close the admin connections Close() // GetReplicationStatus get redis replication information GetReplicationStatus() *ReplicationInfo // ReplicaOfNoOne redis replicaof no one ReplicaOfNoOne(addr string) error // ReplicaOfSource redis replicaof source node ReplicaOfSource(addr, sourceHost, sourcePort string) error }
IReplicationAdmin redis cluster admin interface
func NewReplicationAdmin ¶
func NewReplicationAdmin(addrs []string, options *AdminOptions, log logr.Logger) IReplicationAdmin
NewReplicationAdmin returns new AdminInterface instance at the same time it connects to all Redis ReplicationNodes thanks to the address list
type ImportingSlot ¶
ImportingSlot represents an importing slot (slot + importing from node id)
func (ImportingSlot) String ¶
func (s ImportingSlot) String() string
String string representation of an importing slot
type MigratingSlot ¶
MigratingSlot represents a migrating slot (slot + migrating to node id)
func (MigratingSlot) String ¶
func (s MigratingSlot) String() string
String string representation of a migratting slot
type NodeInfos ¶
type NodeInfos struct { Node *ClusterNode Friends ClusterNodes }
NodeInfos representation of a node info, i.e. data returned by the CLUSTER NODE redis command ClusterNode is the information of the targetted node Friends are the view of the other nodes from the targetted node
func DecodeNodeInfos ¶
DecodeNodeInfos decode from the cmd output the Redis nodes info. Second argument is the node on which we are connected to request info
type ReplicationAdmin ¶
type ReplicationAdmin struct {
// contains filtered or unexported fields
}
ReplicationAdmin wraps redis cluster admin logic
func (*ReplicationAdmin) Close ¶
func (a *ReplicationAdmin) Close()
Close used to close all possible resources instanciate by the ReplicationAdmin
func (*ReplicationAdmin) Connections ¶
func (a *ReplicationAdmin) Connections() IAdminConnections
Connections returns the connection map of all clients
func (*ReplicationAdmin) GetReplicationStatus ¶
func (a *ReplicationAdmin) GetReplicationStatus() *ReplicationInfo
GetReplicationStatus return the ReplicationNodes infos for all nodes
func (*ReplicationAdmin) ReplicaOfNoOne ¶
func (a *ReplicationAdmin) ReplicaOfNoOne(addr string) error
func (*ReplicationAdmin) ReplicaOfSource ¶
func (a *ReplicationAdmin) ReplicaOfSource(addr, sourceHost, sourcePort string) error
type ReplicationInfo ¶
type ReplicationInfo struct {
Nodes map[string]*ReplicationNode
}
func NewReplicationInfo ¶
func NewReplicationInfo() *ReplicationInfo
type ReplicationNode ¶
type ReplicationNode struct { Host string Port string Role string Ready bool SourceHost string SourcePort string }
func DecodeNode ¶
func DecodeNode(input *string, addr string, log logr.Logger) *ReplicationNode
DecodeNode decode from the cmd output the MySQK nodes info. Second argument is the node on which we are connected to request info
func NewDefaultReplicationNode ¶
func NewDefaultReplicationNode() *ReplicationNode
NewDefaultReplicationNode builds and returns new defaultNode instance
func (*ReplicationNode) GetRole ¶
func (n *ReplicationNode) GetRole() composev1alpha1.RedisReplicationRole
GetRole return the Mysql Replication ReplicationNode GetRole
func (*ReplicationNode) GetSourcePort ¶
func (n *ReplicationNode) GetSourcePort() int
func (*ReplicationNode) HostPort ¶
func (n *ReplicationNode) HostPort() string
HostPort returns join Host Port string
type ReplicationNodes ¶
type ReplicationNodes []*ReplicationNode
ReplicationNodes represent a ReplicationNode slice
type Slot ¶
type Slot uint64
Slot represent a Redis Cluster slot
func AddSlots ¶
AddSlots return a new list of slots after adding some slots in it, duplicates are removed
func BuildSlotSlice ¶
BuildSlotSlice return a slice of all slots between this range
func DecodeSlot ¶
DecodeSlot parse a string representation of a slot slot
func RemoveSlot ¶
RemoveSlot return a new list of slot where a specified slot have been removed.
func RemoveSlots ¶
RemoveSlots return a new list of slot where a list of slots have been removed, doesn't work if duplicates
type SlotRange ¶
SlotRange represent a Range of slots
func SlotRangesFromSlots ¶
SlotRangesFromSlots return a slice of slot ranges from a slice of slots