Documentation ¶
Overview ¶
Copyright 2021 kubernetes-app Solutions.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2021 kubernetes-app Solutions.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2021 kubernetes-app Solutions.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2021 kubernetes-app Solutions.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2021 kubernetes-app Solutions.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- Constants
- Variables
- func Contains(s []Slot, e Slot) bool
- func DecodeClusterInfos(input *string) *map[string]string
- 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 *Node) bool
- func MoreByID(n1, n2 *Node) bool
- func NewClient(addr, password string) *redis.Client
- func NewClusterClient(addrs []string, password string) *redis.ClusterClient
- func SetRedisConfig(ctx context.Context, rc *redis.Client, newConfig map[string]string) error
- type Admin
- func (a *Admin) CloseClient()
- func (a *Admin) CloseClusterClient()
- func (a *Admin) GetClusterInfos() (*map[string]string, error)
- func (a *Admin) GetClusterNodes() (*Nodes, error)
- func (a *Admin) GetHashMaxSlot() Slot
- func (a *Admin) SetConfigIfNeed(newConfig map[string]string) error
- func (a *Admin) UpdateMasterConfig(newConfig map[string]string) error
- func (a *Admin) UpdateSlaveConfig(newConfig map[string]string) error
- type AdminInterface
- type ClusterInfosError
- type ClusterStatus
- type Error
- type FindNodeFunc
- type ImportingSlot
- type MigratingSlot
- type Node
- func (n *Node) Clear()
- func (n *Node) GetRole() string
- func (n *Node) HasStatus(flag string) bool
- func (n *Node) IPPort() string
- func (n *Node) SetFailureStatus(flags string)
- func (n *Node) SetLinkStatus(status string)
- func (n *Node) SetReferentMaster(ref string)
- func (n *Node) SetRole(flags string)
- func (n *Node) String() string
- func (n *Node) TotalSlots() int
- type Nodes
- func (n Nodes) CountByFunc(fn func(*Node) bool) (result int)
- func (n Nodes) FilterByFunc(fn func(*Node) bool) Nodes
- func (n Nodes) GetNodeByAddr(addr string) (*Node, error)
- func (n Nodes) GetNodeByID(id string) (*Node, error)
- func (n Nodes) GetNodeByMasterID(id string) (*Node, error)
- func (n Nodes) GetNodesByFunc(f FindNodeFunc) (Nodes, error)
- func (n Nodes) Len() int
- func (n Nodes) Less(i, j int) bool
- func (n Nodes) SortByFunc(less func(*Node, *Node) bool) Nodes
- func (n Nodes) SortNodes() Nodes
- func (n Nodes) String() string
- func (n Nodes) Swap(i, j int)
- type NodesPlacementInfo
- type Slot
- type SlotRange
- type SlotSlice
Constants ¶
const ( // ResetHard HARD mode for RESET command ResetHard = "HARD" // ResetSoft SOFT mode for RESET command ResetSoft = "SOFT" )
const ( // RedisLinkStateConnected redis connection status connected RedisLinkStateConnected = "connected" // RedisLinkStateDisconnected redis connection status disconnected RedisLinkStateDisconnected = "disconnected" )
const ( // NodeStatusPFail Node is in PFAIL state. Not reachable for the node you are contacting, but still logically reachable NodeStatusPFail = "fail?" // NodeStatusFail Node 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 ( // DefaultRedisPort define the default Redis Port DefaultRedisPort = "6379" // RedisMasterRole redis role master RedisMasterRole string = "master" // RedisSlaveRole redis role slave RedisSlaveRole string = "slave" // RedisStandaloneRole redis role standalone RedisStandaloneRole string = "standalone" // RedisNoneRole redis none role RedisNoneRole string = "none" )
const (
// HashMaxSlots Numbers or Redis slots used for Key hashing
HashMaxSlots = 16383
)
Variables ¶
var IsMasterWithNoSlot = func(n *Node) bool { if (n.GetRole() == RedisMasterRole) && (n.TotalSlots() == 0) { return true } return false }
IsMasterWithNoSlot anonymous function for searching Master Node with no slot
var IsMasterWithSlot = func(n *Node) bool { if (n.GetRole() == RedisMasterRole) && (n.TotalSlots() > 0) { return true } return false }
IsMasterWithSlot anonymous function for searching Master Node withslot
var IsSlave = func(n *Node) bool { return n.GetRole() == RedisSlaveRole }
IsSlave anonymous function for searching Slave Node
Functions ¶
func DecodeClusterInfos ¶
DecodeClusterInfos decode from the cmd output the Redis nodes 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 NewClusterClient ¶
func NewClusterClient(addrs []string, password string) *redis.ClusterClient
Types ¶
type Admin ¶
type Admin struct {
// contains filtered or unexported fields
}
Admin wraps redis cluster admin logic
func (*Admin) CloseClient ¶
func (a *Admin) CloseClient()
Close used to close all possible resources instantiate by the Admin
func (*Admin) CloseClusterClient ¶
func (a *Admin) CloseClusterClient()
CloseClusterClient used to close all possible resources instantiate by the Admin
func (*Admin) GetClusterInfos ¶
GetClusterInfos return the Nodes infos for all nodes
func (*Admin) GetClusterNodes ¶
func (*Admin) GetHashMaxSlot ¶
GetHashMaxSlot get the max slot value
func (*Admin) SetConfigIfNeed ¶
SetConfigIfNeed set redis config
func (*Admin) UpdateMasterConfig ¶
UpdateMasterConfig set redis master config
type AdminInterface ¶
type AdminInterface interface { // Connections returns the connection map of all clients // Connections() *redis.Client // CloseClient the admin connections CloseClient() // CloseClusterClient the admin connections CloseClusterClient() // GetClusterInfos get node infos for all nodes GetClusterInfos() (*map[string]string, error) // GetClusterNodes get node infos for all nodes GetClusterNodes() (*Nodes, error) // SetConfigIfNeed set redis config SetConfigIfNeed(newConfig map[string]string) error // GetHashMaxSlot get the max slot value GetHashMaxSlot() Slot }
AdminInterface redis cluster admin interface
func NewAdmin ¶
func NewAdmin(addrs []string, password string) AdminInterface
NewAdmin returns new AdminInterface instance at the same time it connects to all Redis Nodes thanks to the addrs list
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 ClusterStatus ¶
type ClusterStatus string
ClusterStatus Redis Cluster status
const ( // ClusterStatusOK ClusterStatus OK ClusterStatusOK ClusterStatus = "OK" // ClusterStatusKO ClusterStatus KO ClusterStatusKO ClusterStatus = "KO" // ClusterStatusScaling ClusterStatus Scaling ClusterStatusScaling ClusterStatus = "Scaling" // ClusterStatusCalculatingRebalancing ClusterStatus Rebalancing ClusterStatusCalculatingRebalancing ClusterStatus = "Calculating Rebalancing" // ClusterStatusRebalancing ClusterStatus Rebalancing ClusterStatusRebalancing ClusterStatus = "Rebalancing" // ClusterStatusRollingUpdate ClusterStatus RollingUpdate ClusterStatusRollingUpdate ClusterStatus = "RollingUpdate" )
type FindNodeFunc ¶
FindNodeFunc function for finding a Node it is use as input for GetNodeByFunc and GetNodesByFunc
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 Node ¶
type Node 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 Pod *corev1.Pod }
Node Represent a Redis Node
func NewDefaultNode ¶
func NewDefaultNode() *Node
NewDefaultNode builds and returns new defaultNode instance
func (*Node) Clear ¶
func (n *Node) Clear()
Clear used to clear possible ressources attach to the current Node
func (*Node) SetFailureStatus ¶
SetFailureStatus set from inputs flags the possible failure status
func (*Node) SetLinkStatus ¶
SetLinkStatus set the Node link status
func (*Node) SetReferentMaster ¶
SetReferentMaster set the redis node parent referent
func (*Node) TotalSlots ¶
TotalSlots return the total number of slot
type Nodes ¶
type Nodes []*Node
Nodes represent a Node slice
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
func (Nodes) CountByFunc ¶
CountByFunc gives the number elements of NodeSlice that return true for the passed func.
func (Nodes) FilterByFunc ¶
FilterByFunc remove a node from a slice by node ID and returns the slice. If not found, fail silently. Value must be unique
func (Nodes) GetNodeByAddr ¶
GetNodeByAddr returns a Redis Node by its ID if not present in the Nodes slice return an error
func (Nodes) GetNodeByID ¶
GetNodeByID returns a Redis Node by its ID if not present in the Nodes slice return an error
func (Nodes) GetNodeByMasterID ¶
GetNodeByMasterID returns a Redis Node by its ID if not present in the Nodes slice return an error
func (Nodes) GetNodesByFunc ¶
func (n Nodes) GetNodesByFunc(f FindNodeFunc) (Nodes, error)
GetNodesByFunc returns first node found by the FindNodeFunc
func (Nodes) Less ¶
Less reports whether the element with index i should sort before the element with index j.
func (Nodes) SortByFunc ¶
SortByFunc returns a new ordered NodeSlice, determined by a func defining ‘less’.
type NodesPlacementInfo ¶
type NodesPlacementInfo string
NodesPlacementInfo Redis Nodes placement mode information
const ( // NodesPlacementInfoBestEffort the cluster nodes placement is in best effort, // it means you can have 2 masters (or more) on the same VM. NodesPlacementInfoBestEffort NodesPlacementInfo = "BestEffort" // NodesPlacementInfoOptimal the cluster nodes placement is optimal, // it means on master by VM NodesPlacementInfoOptimal NodesPlacementInfo = "Optimal" )
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 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