Documentation ¶
Index ¶
Constants ¶
const ( Port = 6379 // MinimumFailoverSize sets the minimum desired size of Redis replication. // It reflects a simple master - replica pair. // Due to the highly volatile nature of Kubernetes environments // it is better to keep at least 3 instances and feel free to lose one instance for whatever reason. // It is especially useful for scenarios when there is no need or permission to use persistent storage. // In such cases it is safe to run Redis replication failover and the risk of losing data is minimal. MinimumFailoverSize = 2 // INFO REPLICATION fields RoleMaster = "role:master" RoleReplica = "role:slave" // DefaultFailoverTimeout sets the maximum timeout for an exponential backoff timer DefaultFailoverTimeout = 5 * time.Second )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Failover ¶
type Failover interface { Reconfigure() error SelectMaster() *Redis Refresh() error Disconnect() // contains filtered or unexported methods }
Failover speaks for itself
type Redis ¶
type Redis struct { Address Role string ReplicationOffset int // master-specific fields ConnectedReplicas int Replicas Redises // replica-specific fields ReplicaPriority int MasterHost string MasterPort string MasterLinkStatus string // contains filtered or unexported fields }
Redis struct includes a subset of fields returned by INFO
type Rediser ¶
type Rediser interface { Ping() error // contains filtered or unexported methods }
Rediser defines the Redis methods
type Redises ¶
type Redises []Redis
func NewInstances ¶
NewInstances returns a new set of Redis instances. If redis-operator fails to ping and refresh any of the connected instances NewInstances will return an error.
func (Redises) Disconnect ¶
func (instances Redises) Disconnect()
Disconnect closes the connections and releases the resources
func (Redises) Len ¶
sort.Interface implementation for Redises. Allows to choose an instance with a lesser priority and higher replication offset. Note that this assumes that Redises don't have replicas with ReplicaPriority == 0
func (Redises) Reconfigure ¶
Reconfigure checks the state of the Redis replication and tries to fix/initially set the state. There should be only one master. All other instances should report the same master. Working master serves as a source of truth. It means that only those replicas who are not reported by master as its replicas will be reconfigured.
func (Redises) SelectMaster ¶
SelectMaster chooses any working master in case of a working replication or any other master otherwise. Working master in this case is a master with at least one replica connected.