sentinel

package module
v0.0.0-...-fd617c7 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2018 License: MIT Imports: 9 Imported by: 0

README

go-sentinel

Build Status codecov Go Report Card

Package sentinel implements Redis Sentinel pub/sub watcher for golang

Installation

Install go-sentinel using the "go get" command:

go get github.com/ncade/go-sentinel

Documentation

See godoc for package and API descriptions

Usage

// create sentinel watcher with minimal config
snt := sentinel.New(sentinel.Config{
	Password:          "password",
	Addrs:             []string{"localhost:26379"},
	Groups:            []string{"redis01", "redis02", "redis03"},
	RefreshInterval:   45 * time.Second,
	HeartbeatInterval: 10 * time.Second,
	HeartbeatTimeout:  5 * time.Second,
})

// run redis instances discovery for configured groups
// and pub/sub listening for +switch-master, +slave, +sdown, -sdown events
go snt.Run()

defer snt.Stop()

// get master address for 'redis01' master name
master, err := snt.GetMasterAddr("redis01")

// get slaves addresses for 'redis01' master name
slaves, err := snt.GetSlavesAddrs("redis01")

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMasterUnavailable is returned by GetMasterAddr if address is not discovered
	ErrMasterUnavailable = errors.New("cannot discover master from sentinel")
	// ErrInvalidMasterName is retuned by GetMasterAddr, GetSlavesAddrs if master name (group) is not configured
	ErrInvalidMasterName = errors.New("invalid master name")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	// Password for protected Redis instances
	Password string
	// Addrs is a list of redis sentinel instances addresses
	Addrs []string
	// Groups is a list of groups (master names) to discover
	Groups []string

	// DialTimeout specifies the timeout for tcp dial
	DialTimeout time.Duration
	// ReadTimeout specifies the timeout reading from connection
	ReadTimeout time.Duration
	// WriteTimeout specifies the timeout writing to connection
	WriteTimeout time.Duration

	// RefreshInterval specifies the interval for redis instances refresh
	RefreshInterval time.Duration

	// HeartbeatInterval specifies the interval for pub/sub connection healthchecks
	HeartbeatInterval time.Duration
	// HeartbeatTimeout specifies the timeout reading pub/sub connection healthcheck reply
	HeartbeatTimeout time.Duration

	// OnError is the errors hook
	OnError func(err error)
}

Config is a sentinel watcher config

type Sentinel

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

Sentinel is a sentinel watcher

func New

func New(c Config) *Sentinel

New creates sentinel watcher with provided config

func (*Sentinel) GetMasterAddr

func (s *Sentinel) GetMasterAddr(name string) (string, error)

GetMasterAddr returns redis master address

func (*Sentinel) GetSlavesAddrs

func (s *Sentinel) GetSlavesAddrs(name string) ([]string, error)

GetSlavesAddrs returns reachable redis slaves addresses

func (*Sentinel) Run

func (s *Sentinel) Run()

Run starts redis instances discovery and pub/sub updates listening

func (*Sentinel) Stop

func (s *Sentinel) Stop()

Stop initiates graceful shutdown of sentinel watcher. It blocks until all underlying connections are released

Directories

Path Synopsis
Code generated by mockery v1.0.0
Code generated by mockery v1.0.0

Jump to

Keyboard shortcuts

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