leaderredis

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package leaderredis provides a redis driver for package leader

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(driver *RedisDriver)

Option is type of the options to config *RedisDriver

func WithExpiration

func WithExpiration(duration time.Duration) Option

WithExpiration is an option that configures the expiration of redis key. A new round of leader election will start after the key expires.

func WithPollInterval

func WithPollInterval(duration time.Duration) Option

WithPollInterval is an option that configures the poll interval of followers. The followers will periodically try to overthrown the leader, but only succeed when the leader key is missing in redis.

type RedisDriver

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

RedisDriver is a simple redis leader election implementation.

func NewRedisDriver

func NewRedisDriver(client redis.UniversalClient, keyer contract.Keyer, opts ...Option) *RedisDriver

NewRedisDriver creates the newly created *RedisDriver with the given configuration.

func (*RedisDriver) Campaign

func (r *RedisDriver) Campaign(ctx context.Context) error

Campaign starts the leader election using redis. It will bock until this node becomes leader or the context is expired.

func (*RedisDriver) Resign

func (r *RedisDriver) Resign(ctx context.Context) error

Resign gives up the leadership using redis. If the current node is not a leader, this is an no op.

Jump to

Keyboard shortcuts

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