redis

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2019 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
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 Address

type Address struct {
	Host string
	Port string
}

Address represents the Host:Port pair of a Redis instance

func (Address) String

func (a Address) String() string

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

func (*Redis) Ping

func (r *Redis) Ping() error

Ping errs on error if PING failed

type Rediser

type Rediser interface {
	Ping() error
	// contains filtered or unexported methods
}

Rediser defines the Redis methods

type Redises

type Redises []Redis

func NewInstances

func NewInstances(password string, addrs ...Address) (Redises, error)

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

func (instances Redises) Len() int

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

func (instances Redises) Less(i, j int) bool

func (Redises) Reconfigure

func (instances Redises) Reconfigure() (err error)

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

func (instances Redises) Refresh() error

Refresh fetches and refreshes info for all instances

func (Redises) SelectMaster

func (instances Redises) SelectMaster() *Redis

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.

func (Redises) Swap

func (instances Redises) Swap(i, j int)

Jump to

Keyboard shortcuts

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