redis

package
v0.0.0-...-24f4e42 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 13, 2023 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ClusterInfoUnset status of the cluster info: no data set
	ClusterInfoUnset = "Unset"
	// ClusterInfoPartial status of the cluster info: data is not complete (some nodes didn't respond)
	ClusterInfoPartial = "Partial"
	// ClusterInfoInconsistent status of the cluster info: nodeinfos is not consistent between nodes
	ClusterInfoInconsistent = "Inconsistent"
	// ClusterInfoConsistent status of the cluster info: nodeinfos is complete and consistent between nodes
	ClusterInfoConsistent = "Consistent"
)
View Source
const (
	// HashMaxSlots numbers or redis slots used for key hashing
	// as slots start at 0, total number of slots is HashMaxSlots+1
	HashMaxSlots = 16383
	// ResetHard HARD mode for RESET command
	ResetHard = "HARD"
	// ResetSoft SOFT mode for RESET command
	ResetSoft = "SOFT"
)

Redis admin constants

View Source
const (
	// DefaultRedisPort define the default redis port
	DefaultRedisPort = "6379"
	// RedisLinkStateConnected redis connection status connected
	RedisLinkStateConnected = "connected"
	// RedisLinkStateDisconnected redis connection status disconnected
	RedisLinkStateDisconnected = "disconnected"
)
View Source
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. 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"
)
View Source
const (
	// ErrNotFound cannot find a node to connect to
	ErrNotFound = "Unable to find a node to connect"
)

Redis error constants

Variables

View Source
var IsPrimaryWithNoSlot = func(n *Node) bool {
	if (n.GetRole() == v1.RedisClusterNodeRolePrimary) && (n.TotalSlots() == 0) {
		return true
	}
	return false
}

IsPrimaryWithNoSlot anonymous function for searching Primary Node with no slot

View Source
var IsPrimaryWithSlot = func(n *Node) bool {
	if (n.GetRole() == v1.RedisClusterNodeRolePrimary) && (n.TotalSlots() > 0) {
		return true
	}
	return false
}

IsPrimaryWithSlot anonymous function for searching Primary Node withslot

View Source
var IsReplica = func(n *Node) bool {
	return n.GetRole() == v1.RedisClusterNodeRoleReplica
}

IsReplica anonymous function for searching Replica Node

Functions

func Contains

func Contains(s SlotSlice, e Slot) bool

Contains returns true if a node slice contains a node

func DecodeNodeStartTime

func DecodeNodeStartTime(input *string) (time.Time, error)

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) (SlotSlice, *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

func IsInconsistentError(err error) bool

IsInconsistentError returns true if the error is due to cluster inconsistencies

func IsNodeNotFoundedError

func IsNodeNotFoundedError(err error) bool

IsNodeNotFoundedError returns true if the current error is a NodeNotFoundedError

func IsPartialError

func IsPartialError(err error) bool

IsPartialError returns true if the error is due to partial data recovery

func LessByID

func LessByID(n1, n2 *Node) bool

LessByID compare 2 Nodes with there ID

func MoreByID

func MoreByID(n1, n2 *Node) bool

MoreByID compare 2 Nodes with there ID

Types

type Admin

type Admin struct {
	// contains filtered or unexported fields
}

Admin wraps redis cluster admin logic

func (*Admin) AddSlots

func (a *Admin) AddSlots(ctx context.Context, addr string, slots SlotSlice) error

AddSlots uses the ADDSLOTS command to add several slots

func (*Admin) AttachNodeToCluster

func (a *Admin) AttachNodeToCluster(ctx context.Context, addr string) error

AttachNodeToCluster command used to connect a Node to the cluster

func (*Admin) AttachReplicaToPrimary

func (a *Admin) AttachReplicaToPrimary(ctx context.Context, replica *Node, primary *Node) error

AttachReplicaToPrimary attach a replica to a primary node

func (*Admin) Close

func (a *Admin) Close()

Close used to close all possible resources instantiated by the Admin

func (*Admin) Connections

func (a *Admin) Connections() AdminConnectionsInterface

Connections returns the connection map of all clients

func (*Admin) CountKeysInSlot

func (a *Admin) CountKeysInSlot(ctx context.Context, addr string, slot Slot) (int64, error)

CountKeysInSlot exec the redis command to count the number of keys in the given slot on a node

func (*Admin) DelSlots

func (a *Admin) DelSlots(ctx context.Context, addr string, slots SlotSlice) error

DelSlots uses the DELSLOTS command to delete several slots

func (*Admin) DeleteKeys

func (a *Admin) DeleteKeys(ctx context.Context, addr string, keys []string) error

DeleteKeys uses the DEL command to get delete multiple keys

func (*Admin) DetachReplica

func (a *Admin) DetachReplica(ctx context.Context, replica *Node) error

DetachReplica use to detach a replica from a primary

func (*Admin) FlushAll

func (a *Admin) FlushAll(ctx context.Context, addr string) error

FlushAll flush all keys in cluster

func (*Admin) FlushAndReset

func (a *Admin) FlushAndReset(ctx context.Context, 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 (*Admin) ForgetNode

func (a *Admin) ForgetNode(ctx context.Context, id string) error

ForgetNode used to force other redis cluster node to forget a specific node

func (*Admin) ForgetNodeByAddr

func (a *Admin) ForgetNodeByAddr(ctx context.Context, addr string) error

ForgetNodeByAddr used to force other redis cluster node to forget a specific node

func (*Admin) GetClusterInfos

func (a *Admin) GetClusterInfos(ctx context.Context) (*ClusterInfos, error)

GetClusterInfos return the Nodes infos for all nodes

func (*Admin) GetClusterInfosSelected

func (a *Admin) GetClusterInfosSelected(ctx context.Context, addrs []string) (*ClusterInfos, error)

GetClusterInfosSelected return the Nodes infos for all nodes selected in the cluster

func (*Admin) GetConfig

func (a *Admin) GetConfig(ctx context.Context, pattern string) (map[string]string, error)

GetConfig gets the running redis server configuration matching the pattern

func (*Admin) GetHashMaxSlot

func (a *Admin) GetHashMaxSlot() Slot

GetHashMaxSlot get the max slot value

func (*Admin) GetKeys

func (a *Admin) GetKeys(ctx context.Context, addr string, slot Slot, batch string) ([]string, error)

GetKeys uses the GETKEYSINSLOT command to get the number of keys specified by keyBatch

func (*Admin) GetKeysInSlot

func (a *Admin) GetKeysInSlot(ctx context.Context, addr string, slot Slot, batch string, limit bool) ([]string, error)

GetKeysInSlot exec the redis command to get the keys in the given slot on the node we are connected to Batch is the number of keys fetch per batch, Limit can be use to limit to one batch

func (*Admin) InitRedisCluster

func (a *Admin) InitRedisCluster(ctx context.Context, addr string) error

InitRedisCluster used to init a single node redis cluster

func (*Admin) MigrateKeys

func (a *Admin) MigrateKeys(ctx context.Context, source *Node, dest *Node, slots SlotSlice, spec *rapi.RedisClusterSpec, replace, scaling bool, primaries Nodes) error

MigrateKeys from the source node to the destination node. If replace is true, replace key on busy error. Timeout is in milliseconds

func (*Admin) RebuildConnectionMap

func (a *Admin) RebuildConnectionMap(ctx context.Context, addrs []string, options *AdminOptions)

RebuildConnectionMap rebuild the connection map according to the given addresses

func (*Admin) SetConfig

func (a *Admin) SetConfig(ctx context.Context, addr string, config []string) error

SetConfig sets the specified redis server configuration

func (*Admin) SetSlot

func (a *Admin) SetSlot(ctx context.Context, addr, action string, slot Slot, node *Node) error

func (*Admin) SetSlots

func (a *Admin) SetSlots(ctx context.Context, addr, action string, slots SlotSlice, nodeID string, retryAttempt int) error

SetSlots used to set SETSLOT command on several slots

func (*Admin) StartFailover

func (a *Admin) StartFailover(ctx context.Context, addr string) error

StartFailover used to force the failover of a specific redis primary node

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(ctx context.Context, addr string) error

Add connect to the given address and register the client connection to the map

func (*AdminConnections) AddAll

func (cnx *AdminConnections) AddAll(ctx context.Context, addrs []string)

AddAll connect the given list of addresses and add them to the connection map fail silently

func (*AdminConnections) Close

func (cnx *AdminConnections) Close()

Close used to close all possible resources instantiated by the Connections

func (*AdminConnections) Get

Get returns a client connection for the given adress, connects if the connection is not in the map yet

func (*AdminConnections) GetAll

func (cnx *AdminConnections) GetAll() map[string]ClientInterface

GetAll returns a map of all clients per address

func (*AdminConnections) GetDifferentFrom

func (cnx *AdminConnections) GetDifferentFrom(addr string) (ClientInterface, error)

GetDifferentFrom returns random a client connection different from given address

func (*AdminConnections) GetRandom

func (cnx *AdminConnections) GetRandom() (ClientInterface, 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]ClientInterface

GetSelected returns a map of clients based on the input addresses

func (*AdminConnections) Reconnect

func (cnx *AdminConnections) Reconnect(ctx context.Context, addr string) error

Reconnect force a reconnection on the given address if the address 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(ctx context.Context, 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(ctx context.Context, addr string) (ClientInterface, error)

Update returns a client connection for the given adress, connects if the connection is not in the map yet

func (*AdminConnections) ValidateResp

func (cnx *AdminConnections) ValidateResp(ctx context.Context, resp interface{}, err error, addr, errMessage string) error

ValidateResp checks the redis resp is empty and will attempt to reconnect on connection error. In case of error, customize the error, log it and return it.

type AdminConnectionsInterface

type AdminConnectionsInterface interface {
	// Add connect to the given address and
	// register the client connection to the pool
	Add(ctx context.Context, 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(ctx context.Context, addr string) (ClientInterface, error)
	// GetRandom returns a client connection to a random node of the client map
	GetRandom() (ClientInterface, error)
	// GetDifferentFrom returns a random client connection different from given address
	GetDifferentFrom(addr string) (ClientInterface, error)
	// GetAll returns a map of all clients per address
	GetAll() map[string]ClientInterface
	//GetSelected returns a map of clients based on the input addresses
	GetSelected(addrs []string) map[string]ClientInterface
	// Reconnect force a reconnection on the given address
	// if the adress is not part of the map, act like Add
	Reconnect(ctx context.Context, addr string) error
	// AddAll connect to the given list of addresses and
	// register them in the map
	// fail silently
	AddAll(ctx context.Context, addrs []string)
	// ReplaceAll clear the map and re-populate it with new connections
	// fail silently
	ReplaceAll(ctx context.Context, addrs []string)
	// ValidateResp checks if the redis resp is empty and will attempt to reconnect on connection error.
	// In case of error, customize the error, log it and return it.
	ValidateResp(ctx context.Context, resp interface{}, err error, addr, errMessage string) error
	// Reset close all connections and clear the connection map
	Reset()
}

AdminConnectionsInterface interface representing the map of admin connections to redis cluster nodes

func NewAdminConnections

func NewAdminConnections(ctx context.Context, addrs []string, options *AdminOptions) AdminConnectionsInterface

NewAdminConnections returns and instance of AdminConnectionsInterface

type AdminInterface

type AdminInterface interface {
	// Connections returns the connection map of all clients
	Connections() AdminConnectionsInterface
	// Close the admin connections
	Close()
	// InitRedisCluster configures the first node of a cluster
	InitRedisCluster(ctx context.Context, addr string) error
	// GetClusterInfos gets node info for all nodes
	GetClusterInfos(ctx context.Context) (*ClusterInfos, error)
	// GetClusterInfosSelected returns the node info for all selected nodes in the cluster
	GetClusterInfosSelected(ctx context.Context, addrs []string) (*ClusterInfos, error)
	// AttachNodeToCluster connects a Node to the cluster
	AttachNodeToCluster(ctx context.Context, addr string) error
	// AttachReplicaToPrimary attaches a replica to a primary node
	AttachReplicaToPrimary(ctx context.Context, replica *Node, primary *Node) error
	// DetachReplica detaches a replica from a primary
	DetachReplica(ctx context.Context, replica *Node) error
	// StartFailover executes the failover of a redis primary with the corresponding addr
	StartFailover(ctx context.Context, addr string) error
	// ForgetNode forces the cluster to forget a node
	ForgetNode(ctx context.Context, id string) error
	// ForgetNodeByAddr forces the cluster to forget the node with the specified address
	ForgetNodeByAddr(ctx context.Context, addr string) error
	// SetSlot sets a single slot
	SetSlot(ctx context.Context, addr, action string, slot Slot, node *Node) error
	// SetSlots sets multiple slots in a pipeline
	SetSlots(ctx context.Context, addr string, action string, slots SlotSlice, nodeID string, retryAttempt int) error
	// AddSlots adds slots in a pipeline
	AddSlots(ctx context.Context, addr string, slots SlotSlice) error
	// DelSlots deletes slots in a pipeline
	DelSlots(ctx context.Context, addr string, slots SlotSlice) error
	// GetKeysInSlot gets the keys in the given slot on the node
	GetKeysInSlot(ctx context.Context, addr string, slot Slot, batch string, limit bool) ([]string, error)
	// CountKeysInSlot counts the keys in a given slot on the node
	CountKeysInSlot(ctx context.Context, addr string, slot Slot) (int64, error)
	// GetKeys gets keys in a slot
	GetKeys(ctx context.Context, addr string, slot Slot, batch string) ([]string, error)
	// DeleteKeys deletes keys
	DeleteKeys(ctx context.Context, addr string, keys []string) error
	// MigrateKeys migrates keys from the source to destination node and returns number of slot migrated
	MigrateKeys(ctx context.Context, source *Node, dest *Node, slots SlotSlice, spec *rapi.RedisClusterSpec, replace, scaling bool, primaries Nodes) error
	// FlushAndReset flushes and resets the cluster configuration of the node
	FlushAndReset(ctx context.Context, addr string, mode string) error
	// FlushAll flushes all keys in the cluster
	FlushAll(ctx context.Context, addr string) error
	// GetHashMaxSlot gets the max slot value
	GetHashMaxSlot() Slot
	// RebuildConnectionMap rebuilds the connection map according to the given addresses
	RebuildConnectionMap(ctx context.Context, addrs []string, options *AdminOptions)
	// GetConfig gets the running redis server configuration matching the pattern
	GetConfig(ctx context.Context, pattern string) (map[string]string, error)
	// SetConfig sets the specified redis server configuration
	SetConfig(ctx context.Context, addr string, config []string) error
}

AdminInterface redis cluster admin interface

func NewAdmin

func NewAdmin(ctx context.Context, addrs []string, options *AdminOptions) AdminInterface

NewAdmin returns new AdminInterface instance at the same time it connects to all Redis Nodes thanks to the address list

func NewRedisAdmin

func NewRedisAdmin(ctx context.Context, pods []corev1.Pod, cfg *config.Redis) (AdminInterface, error)

NewRedisAdmin builds and returns new Admin from the list of pods

type AdminOptions

type AdminOptions struct {
	ConnectionTimeout  time.Duration
	ClientName         string
	RenameCommandsFile string
}

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 NewClient

func NewClient(ctx context.Context, addr string, cnxTimeout time.Duration, commandsMapping map[string]string) (*Client, error)

NewClient build a client connection and connect to a redis address

func (*Client) Close

func (c *Client) Close() error

Close closes the connection.

func (*Client) DoCmd

func (c *Client) DoCmd(ctx context.Context, rcv interface{}, cmd string, args ...string) error

DoCmd calls the given Redis command.

func (*Client) DoCmdWithRetries

func (c *Client) DoCmdWithRetries(ctx context.Context, rcv interface{}, cmd string, args ...string) error

DoCmdWithRetries calls the given Redis command.

func (*Client) DoPipe

func (c *Client) DoPipe(ctx context.Context) error

DoPipe executes all the commands in the pipeline.

func (*Client) PipeAppend

func (c *Client) PipeAppend(action radix.Action)

PipeAppend adds the given call to the pipeline queue.

func (*Client) PipeReset

func (c *Client) PipeReset()

PipeReset discards all Actions and resets all internal state.

type ClientInterface

type ClientInterface interface {
	// Close closes the connection.
	Close() error

	// DoCmd calls the given Redis command and retrieves a result.
	DoCmd(ctx context.Context, rcv interface{}, cmd string, args ...string) error

	// DoCmdWithRetries calls the given Redis command and retrieves a result with retires.
	DoCmdWithRetries(ctx context.Context, rcv interface{}, cmd string, args ...string) error

	// PipeAppend adds the given call to the pipeline queue.
	PipeAppend(action radix.Action)

	// PipeReset discards all Actions and resets all internal state.
	PipeReset()

	// DoPipe executes all of the commands in the pipeline.
	DoPipe(ctx context.Context) error
}

ClientInterface redis client interface

type Cluster

type Cluster struct {
	Name           string
	Namespace      string
	NodeSelector   map[string]string
	Nodes          map[string]*Node
	KubeNodes      []corev1.Node
	Status         rapi.ClusterStatus
	NodesPlacement rapi.NodesPlacementInfo
	ActionsInfo    ClusterActionsInfo
}

Cluster represents a Redis Cluster

func NewCluster

func NewCluster(name, namespace string) *Cluster

NewCluster builds and returns new Cluster instance

func (*Cluster) AddNode

func (c *Cluster) AddNode(node *Node)

AddNode used to add new Node in the cluster if node with the same ID is already present in the cluster the previous Node is replaced

func (*Cluster) GetNodeByFunc

func (c *Cluster) GetNodeByFunc(f FindNodeFunc) (*Node, error)

GetNodeByFunc returns first node found by the FindNodeFunc

func (*Cluster) GetNodeByID

func (c *Cluster) GetNodeByID(id string) (*Node, error)

GetNodeByID returns a Cluster Node by its ID if not present in the cluster return an error

func (*Cluster) GetNodeByIP

func (c *Cluster) GetNodeByIP(ip string) (*Node, error)

GetNodeByIP returns a Cluster Node by its ID if not present in the cluster return an error

func (*Cluster) GetNodeByPodName

func (c *Cluster) GetNodeByPodName(name string) (*Node, error)

GetNodeByPodName returns a Cluster Node by its Pod name if not present in the cluster return an error

func (*Cluster) GetNodesByFunc

func (c *Cluster) GetNodesByFunc(f FindNodeFunc) (Nodes, error)

GetNodesByFunc returns first node found by the FindNodeFunc

func (*Cluster) GetZone

func (c *Cluster) GetZone(nodeName string) string

GetZone gets the zone label from the specified k8s node

func (*Cluster) GetZones

func (c *Cluster) GetZones() []string

GetZones gets all available zones from the list of k8s nodes

func (*Cluster) ToAPIClusterStatus

func (c *Cluster) ToAPIClusterStatus() rapi.RedisClusterState

ToAPIClusterStatus convert the Cluster information to a api

type ClusterActionsInfo

type ClusterActionsInfo struct {
	NbSlotsToMigrate int32
}

ClusterActionsInfo stores information about the current action on the Cluster

type ClusterInconsistencies

type ClusterInconsistencies map[Slot]OwneshipView

ClusterInconsistencies structure representing inconsistencies in the cluster

func (ClusterInconsistencies) String

func (ci ClusterInconsistencies) String() string

String

type ClusterInfos

type ClusterInfos struct {
	Infos  map[string]*NodeInfos
	Status string
}

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() bool

ComputeStatus checks the ClusterInfos status based on the current data. The status ClusterInfoPartial is set while building the ClusterInfos. If already set, do nothing. Returns true if consistent or on error.

func (*ClusterInfos) GetInconsistencies

func (c *ClusterInfos) GetInconsistencies() *ClusterInconsistencies

GetInconsistencies returns a view of the inconsistent configuration per slot

func (*ClusterInfos) GetNodes

func (c *ClusterInfos) GetNodes() Nodes

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) Error

func (e ClusterInfosError) Error() string

Error error string

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 ConfigSignature

type ConfigSignature map[string]SlotSlice

ConfigSignature Represents the slots of each node

func (ConfigSignature) String

func (c ConfigSignature) String() string

String representation of a ConfigSignaure

type Error

type Error string

Error used to represent an error

func (Error) Error

func (e Error) Error() string

type FindNodeFunc

type FindNodeFunc func(node *Node) bool

FindNodeFunc function for finding a Node it is use as input for GetNodeByFunc and GetNodesByFunc

type ImportingSlot

type ImportingSlot struct {
	SlotID     Slot   `json:"slot"`
	FromNodeID string `json:"fromNodeId"`
}

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

type MigratingSlot struct {
	SlotID   Slot   `json:"slot"`
	ToNodeID string `json:"toNodeId"`
}

MigratingSlot represents a migrating slot (slot + migrating to node id)

func (MigratingSlot) String

func (s MigratingSlot) String() string

String string representation of a migrating slot

type Node

type Node struct {
	ID              string
	IP              string
	Port            string
	Role            string
	Zone            string
	LinkState       string
	PrimaryReferent string
	FailStatus      []string
	PingSent        int64
	PongRecv        int64
	ConfigEpoch     int64
	Slots           SlotSlice
	MigratingSlots  map[Slot]string
	ImportingSlots  map[Slot]string
	ServerStartTime time.Time

	Pod *kapiv1.Pod
}

Node represents a Redis Node

func NewDefaultNode

func NewDefaultNode() *Node

NewDefaultNode builds and returns new defaultNode instance

func NewNode

func NewNode(id, ip string, pod *kapiv1.Pod) *Node

NewNode builds and returns new Node instance

func (*Node) Clear

func (n *Node) Clear()

Clear used to clear possible resources attach to the current Node

func (*Node) GetRole

func (n *Node) GetRole() v1.RedisClusterNodeRole

GetRole returns the Redis Cluster Node's role

func (*Node) HasStatus

func (n *Node) HasStatus(flag string) bool

HasStatus returns true if the node has the provided fail status flag

func (*Node) IPPort

func (n *Node) IPPort() string

IPPort returns join Ip Port string

func (*Node) SetFailureStatus

func (n *Node) SetFailureStatus(flags string)

SetFailureStatus set from inputs flags the possible failure status

func (*Node) SetLinkStatus

func (n *Node) SetLinkStatus(status string) error

SetLinkStatus set the Node link status

func (*Node) SetPrimaryReferent

func (n *Node) SetPrimaryReferent(ref string)

SetPrimaryReferent set the redis node parent referent

func (*Node) SetRole

func (n *Node) SetRole(flags string) error

SetRole from a flags string list set the Node's role

func (*Node) String

func (n *Node) String() string

String string representation of a Redis Node instance

func (*Node) ToAPINode

func (n *Node) ToAPINode() v1.RedisClusterNode

ToAPINode used to convert the current Node to an API v1alpha1.RedisClusterNode

func (*Node) TotalSlots

func (n *Node) TotalSlots() int

TotalSlots return the total number of slot

type NodeInfos

type NodeInfos struct {
	Node    *Node
	Friends Nodes
}

NodeInfos representation of a node info, i.e. data returned by the CLUSTER NODES redis command Node is the information of the targeted node Friends are the view of the other nodes from the targeted node

func DecodeNodeInfos

func DecodeNodeInfos(input *string, addr string) *NodeInfos

DecodeNodeInfos decode from the cmd output the Redis nodes info. Second argument is the node on which we are connected to request info

func NewNodeInfos

func NewNodeInfos() *NodeInfos

NewNodeInfos returns an instance of NodeInfo

type Nodes

type Nodes []*Node

Nodes represent a Node slice

func (Nodes) CountByFunc

func (n Nodes) CountByFunc(fn func(*Node) bool) (result int)

CountByFunc gives the number elements of NodeSlice that return true for the passed func.

func (Nodes) FilterByFunc

func (n Nodes) FilterByFunc(fn func(*Node) bool) Nodes

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) GetNodeByID

func (n Nodes) GetNodeByID(id string) (*Node, error)

GetNodeByID 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) Len

func (n Nodes) Len() int

Len is the number of elements in the collection.

func (Nodes) Less

func (n Nodes) Less(i, j int) bool

Less reports whether the element with index i should sort before the element with index j.

func (Nodes) SortByFunc

func (n Nodes) SortByFunc(less func(*Node, *Node) bool) Nodes

SortByFunc returns a new ordered NodeSlice, determined by a func defining ‘less’.

func (Nodes) SortNodes

func (n Nodes) SortNodes() Nodes

SortNodes sort Nodes and return the sorted Nodes

func (Nodes) String

func (n Nodes) String() string

func (Nodes) Swap

func (n Nodes) Swap(i, j int)

Swap swaps the elements with indexes i and j.

type OwnerWithStatus

type OwnerWithStatus struct {
	Addr   string
	Status string
}

OwnerWithStatus represents a node owner and the way it sees the slot

type OwneshipView

type OwneshipView map[OwnerWithStatus][]string

OwneshipView map representing who owns a slot and who sees it

type Slot

type Slot uint64

Slot represent a Redis Cluster slot

func DecodeSlot

func DecodeSlot(s string) (Slot, error)

DecodeSlot parses a string representation of a slot slot

func (Slot) String

func (s Slot) String() string

String string representation of a slot

type SlotRange

type SlotRange struct {
	Min Slot `json:"min"`
	Max Slot `json:"max"`
}

SlotRange represent a Range of slots

func SlotRangesFromSlots

func SlotRangesFromSlots(slots SlotSlice) []SlotRange

SlotRangesFromSlots return a slice of slot ranges from a slice of slots

func (SlotRange) String

func (s SlotRange) String() string

String string representation of a slot range

func (SlotRange) Total

func (s SlotRange) Total() int

Total returns total slot present in the range

type SlotSlice

type SlotSlice []Slot

SlotSlice attaches the methods of sort.Interface to []string, sorting in increasing order.

func AddSlots

func AddSlots(slots SlotSlice, addedSlots SlotSlice) SlotSlice

AddSlots return a new list of slots after adding some slots in it, duplicates are removed

func BuildSlotSlice

func BuildSlotSlice(min, max Slot) SlotSlice

BuildSlotSlice return a slice of all slots between this range

func RemoveSlots

func RemoveSlots(slots SlotSlice, removedSlots SlotSlice) SlotSlice

RemoveSlots return a new list of slot where a list of slots have been removed, doesn't work if duplicates

func (SlotSlice) ConvertToStrings

func (s SlotSlice) ConvertToStrings() []string

func (SlotSlice) Len

func (s SlotSlice) Len() int

func (SlotSlice) Less

func (s SlotSlice) Less(i, j int) bool

func (SlotSlice) String

func (s SlotSlice) String() string

func (SlotSlice) Swap

func (s SlotSlice) Swap(i, j int)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL