Documentation
¶
Overview ¶
Package rediscoord provides Redis-backed cron.Claimer and cron.Elector implementations.
Index ¶
Constants ¶
const ( // DefaultClaimTTL is the time a fire claim remains reserved. It must cover // the largest expected jitter, clock skew, and delayed catch-up window. DefaultClaimTTL = 10 * time.Minute // DefaultClaimPrefix namespaces fire claims in Redis. DefaultClaimPrefix = "cron:claim:" )
const ( // DefaultLeaderKey is the Redis key holding the leadership lease. DefaultLeaderKey = "cron:leader" // DefaultLeaderTTL is the leadership lease. Failover can take one TTL. DefaultLeaderTTL = 30 * time.Second )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Claimer ¶
type Claimer struct {
// contains filtered or unexported fields
}
Claimer stores fire claims with SET NX and retains them until their TTL.
func NewClaimer ¶
func NewClaimer(client redis.UniversalClient, opts ...ClaimerOption) (*Claimer, error)
NewClaimer constructs a Redis fire Claimer. It returns an error for a nil client, a nil option, or an option that rejects its argument.
type ClaimerOption ¶
type ClaimerOption func(*claimerConfig) error
ClaimerOption configures a Claimer.
func WithClaimPrefix ¶
func WithClaimPrefix(prefix string) ClaimerOption
WithClaimPrefix overrides DefaultClaimPrefix. An empty prefix is allowed.
func WithClaimTTL ¶
func WithClaimTTL(ttl time.Duration) ClaimerOption
WithClaimTTL overrides DefaultClaimTTL. A ttl below one millisecond is rejected.
type Elector ¶
type Elector struct {
// contains filtered or unexported fields
}
Elector is a lease-based cron.Elector. IsLeader renews a lease already held by this process; no background goroutine or Close is required.
func NewElector ¶
func NewElector(client redis.UniversalClient, opts ...ElectorOption) (*Elector, error)
NewElector constructs a lease-based Redis Elector with a random process identity. It returns an error for a nil client, a nil option, an option that rejects its argument, or a failure of the system random source.
type ElectorOption ¶
type ElectorOption func(*electorConfig) error
ElectorOption configures an Elector.
func WithLeaderKey ¶
func WithLeaderKey(key string) ElectorOption
WithLeaderKey overrides DefaultLeaderKey. The key is trimmed; an empty key is rejected.
func WithLeaderTTL ¶
func WithLeaderTTL(ttl time.Duration) ElectorOption
WithLeaderTTL overrides DefaultLeaderTTL. A ttl below one millisecond is rejected.