redleader

package module
v0.0.0-...-8c7a5bd Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2023 License: MIT Imports: 8 Imported by: 0

README

redleader

an implementation of leader election using Redis as the coordination mechanism:

  • Redis
  • Leadership election.

example

setup redis servers

git clone github.com/dtest11/redleader
cd redleader
make setup
go run example/main.go

you can check example/main.go

alt text

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunWithPoll

func RunWithPoll(ctx context.Context, lec LeaderElectionConfig, rs *redsync.Redsync) error

RunWithPoll use redsync to leader elect

Types

type LeaderCallbacks

type LeaderCallbacks struct {
	OnStartedLeading func(context.Context)
	OnStoppedLeading func()
}

type LeaderElectionConfig

type LeaderElectionConfig struct {
	Callbacks             LeaderCallbacks
	LockKey               string
	LeaseDuration         time.Duration // leader lease time
	ExtendPeriodDuration  time.Duration // extend lock period
	NewLockPeriodDuration time.Duration // attempt get lock
}

type LeaderElector

type LeaderElector struct {
	RedSync *redsync.Redsync
	// contains filtered or unexported fields
}

func NewLeaderElector

func NewLeaderElector(conf LeaderElectionConfig, rs *redsync.Redsync) *LeaderElector

func (*LeaderElector) Acquire

func (le *LeaderElector) Acquire(ctx context.Context) error

Acquire attempt get lock and extend lock

func (*LeaderElector) IsLeader

func (le *LeaderElector) IsLeader() bool

IsLeader check current server is leader

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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