Help us shape the future of Go! Take the 2026 Go Developer Survey

memstore

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package memstore is an in-process implementation of leaderelection.Store.

It is the reference the acceptance suite validates itself against, and it is useful in an application's own tests: an election backed by memstore exercises the real leaderelection.Elector -- promotion, renewal, watchdog, fencing -- without a database.

It elects a leader among goroutines in one process only. Processes do not share it, so it is not a substitute for the postgres or mysql stores.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Store)

Option configures a Store.

func WithNow

func WithNow(now func() time.Time) Option

WithNow overrides the clock. Tests use it to make expiry deterministic instead of sleeping.

type Store

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

Store keeps leases in memory. The zero value is not usable; call New.

Being in-process, Store is its own clock authority, which is precisely the role the database plays for the real stores: every timestamp it reports, including Lease.Now, comes from the same source.

func New

func New(opts ...Option) *Store

New returns an empty Store.

func (*Store) Acquire

func (s *Store) Acquire(ctx context.Context, name, identity string, ttl time.Duration, payload []byte) (leaderelection.Lease, error)

Acquire implements leaderelection.Store.

func (*Store) Inspect

func (s *Store) Inspect(ctx context.Context, name string) (leaderelection.Lease, error)

Inspect implements leaderelection.Store.

func (*Store) Release

func (s *Store) Release(ctx context.Context, name, identity string, fence int64) error

Release implements leaderelection.Store.

func (*Store) Renew

func (s *Store) Renew(ctx context.Context, name, identity string, fence int64, ttl time.Duration, payload []byte) (leaderelection.Lease, error)

Renew implements leaderelection.Store.

Jump to

Keyboard shortcuts

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