Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// TTL is the time-to-live for the leader lock
TTL time.Duration
// RenewalInterval is how often to renew the leader lock
RenewalInterval time.Duration
// NodeID is the unique identifier for this node
// If empty, a random ID will be generated
NodeID string
}
Config holds configuration for leader election.
type Elector ¶
type Elector interface {
// Start begins the leader election process
Start(ctx context.Context) error
// Stop gracefully stops the leader election
Stop(ctx context.Context) error
// IsLeader returns true if this node is currently the leader
IsLeader() bool
// LeadershipChannel returns a channel that receives leadership changes
// true = gained leadership, false = lost leadership
LeadershipChannel() <-chan bool
// GetLeaderID returns the current leader's ID
GetLeaderID() (string, error)
}
Elector defines the interface for leader election implementations.
type RedisElector ¶
type RedisElector struct {
// contains filtered or unexported fields
}
RedisElector implements leader election using Redis.
func NewRedisElector ¶
func NewRedisElector(client *redis.Client, log logrus.FieldLogger, keyName string, config *Config) (*RedisElector, error)
NewRedisElector creates a new Redis-based leader elector.
func (*RedisElector) GetLeaderID ¶
func (e *RedisElector) GetLeaderID() (string, error)
GetLeaderID returns the current leader's ID.
func (*RedisElector) IsLeader ¶
func (e *RedisElector) IsLeader() bool
IsLeader returns true if this node is currently the leader.
func (*RedisElector) LeadershipChannel ¶
func (e *RedisElector) LeadershipChannel() <-chan bool
LeadershipChannel returns a channel that receives leadership changes.
Click to show internal directories.
Click to hide internal directories.