rediscoord

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package rediscoord provides Redis-backed cron.Claimer and cron.Elector implementations.

Index

Constants

View Source
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:"
)
View Source
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.

func (*Claimer) Claim

func (c *Claimer) Claim(ctx context.Context, fireKey string) (bool, error)

Claim reserves fireKey with SET NX until the TTL expires. false, nil means another scheduler instance already holds it. A nil ctx or an empty key is rejected; Redis failures are returned wrapped, so the scheduler skips the fire with cron.SkipClaimError.

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.

func (*Elector) IsLeader

func (e *Elector) IsLeader(ctx context.Context) (bool, error)

IsLeader acquires the lease when it is free, renews it when this process holds it, and returns false, nil while another process owns it. A nil ctx is rejected; Redis failures are returned wrapped, so the scheduler skips the fire with cron.SkipElectionError.

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.

Jump to

Keyboard shortcuts

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