Documentation
¶
Index ¶
- func New(ctx context.Context, cfg RedisLeaderElectionConfig) (leaderelection.LeaderElector, error)
- func NewWithConn(ctx context.Context, client *redis.Client, cfg RedisLeaderElectionConfig) (leaderelection.LeaderElector, error)
- type RedisLeaderElection
- func (rle *RedisLeaderElection) AcquireLeadership(ctx context.Context) (bool, error)
- func (rle *RedisLeaderElection) CheckLeadership(ctx context.Context) (bool, error)
- func (rle *RedisLeaderElection) Close()
- func (rle *RedisLeaderElection) RelinquishLeadership(ctx context.Context) (bool, error)
- func (rle *RedisLeaderElection) Run(ctx context.Context) error
- type RedisLeaderElectionConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
func New(ctx context.Context, cfg RedisLeaderElectionConfig) (leaderelection.LeaderElector, error)
Initialize leader election with redis parameters and lock id
func NewWithConn ¶
func NewWithConn(ctx context.Context, client *redis.Client, cfg RedisLeaderElectionConfig) (leaderelection.LeaderElector, error)
Initialize leader election with redis client and lock id. Caller must have connected to redis and gives us a client to work with. Redis parameters can be skipped in this case. Please note, this Redis client will be dedicated for leader election only. Redis implementation will ignore RelinquishIntervalSpec. Redis distributed locking described here https://redis.io/docs/latest/develop/use/patterns/distributed-locks/, relies on TTL of the SET value. This crucially covers for the case where the instance holding the lock just vanishes. RelinquishIntervalSpec is used for cases where the user wants leadership handoff every day for e.g. Setting TTL to a day will result in a very long wait time before leadership handoff takes place in case where the leader vanishes.
Types ¶
type RedisLeaderElection ¶
type RedisLeaderElection struct {
leaderelection.LeaderElection
// contains filtered or unexported fields
}
func (*RedisLeaderElection) AcquireLeadership ¶ added in v0.1.5
func (rle *RedisLeaderElection) AcquireLeadership(ctx context.Context) (bool, error)
func (*RedisLeaderElection) CheckLeadership ¶ added in v0.1.5
func (rle *RedisLeaderElection) CheckLeadership(ctx context.Context) (bool, error)
func (*RedisLeaderElection) Close ¶ added in v0.1.6
func (rle *RedisLeaderElection) Close()
Close the election
func (*RedisLeaderElection) RelinquishLeadership ¶
func (rle *RedisLeaderElection) RelinquishLeadership(ctx context.Context) (bool, error)
Relinquish leadership. A follower calling this function will be returned an error.
type RedisLeaderElectionConfig ¶
type RedisLeaderElectionConfig struct {
Host string
Port uint16
Secure bool
InsecureSkipVerify bool
Password string
leaderelection.LeaderElectionConfig
}
Redis client parameters and lock id