idempotencyredis

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: May 2, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package idempotencyredis provides Redis-backed idempotency storage.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LegacyInFlightRecoveryEvent added in v2.1.0

type LegacyInFlightRecoveryEvent struct {
	// Key is hashed by default. It contains the raw key only when
	// Options.LegacyInFlightRecoveryRawKey is explicitly enabled.
	Key string
	// KeyHash always contains the hashed key value when a key is available.
	KeyHash string
	// RawKey is populated only when LegacyInFlightRecoveryRawKey is explicitly enabled.
	RawKey  string
	Outcome LegacyInFlightRecoveryOutcome
}

LegacyInFlightRecoveryEvent carries structured context for legacy token recovery.

type LegacyInFlightRecoveryHandler added in v2.1.0

type LegacyInFlightRecoveryHandler interface {
	HandleLegacyInFlightRecovery(context.Context, LegacyInFlightRecoveryEvent)
}

LegacyInFlightRecoveryHandler is invoked when a tokenless legacy recovery branch is encountered. Keep handlers fast and non-blocking.

type LegacyInFlightRecoveryHandlerFunc added in v2.1.0

type LegacyInFlightRecoveryHandlerFunc func(context.Context, LegacyInFlightRecoveryEvent)

LegacyInFlightRecoveryHandlerFunc adapts a function into a LegacyInFlightRecoveryHandler.

func (LegacyInFlightRecoveryHandlerFunc) HandleLegacyInFlightRecovery added in v2.1.0

func (f LegacyInFlightRecoveryHandlerFunc) HandleLegacyInFlightRecovery(ctx context.Context, event LegacyInFlightRecoveryEvent)

HandleLegacyInFlightRecovery calls f when f is not nil.

type LegacyInFlightRecoveryOutcome added in v2.1.0

type LegacyInFlightRecoveryOutcome string

LegacyInFlightRecoveryOutcome captures whether a legacy tokenless recovery path was exercised in the adapter.

const (
	// LegacyInFlightRecoveryRecovered indicates tokenless legacy in-flight state
	// was intentionally migrated away.
	LegacyInFlightRecoveryRecovered LegacyInFlightRecoveryOutcome = "legacy_in_flight_recovered"
	// LegacyInFlightRecoveryTokenMismatch indicates a token was supplied for a
	// tokenless legacy in-flight record and release was rejected.
	LegacyInFlightRecoveryTokenMismatch LegacyInFlightRecoveryOutcome = "legacy_in_flight_token_mismatch"
)

type Options

type Options struct {
	KeyPrefix string
	// OnLegacyInFlightRecovery receives structured recovery telemetry.
	OnLegacyInFlightRecovery LegacyInFlightRecoveryHandler
	// LegacyInFlightRecoveryRawKey exposes raw idempotency keys in recovery events.
	// Defaults to false so adapter telemetry receives hashed keys.
	LegacyInFlightRecoveryRawKey bool
}

Options configures Redis-backed idempotency storage.

type Store

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

Store implements ports.IdempotencyStore using Redis.

func New

func New(client redis.UniversalClient, opts Options) *Store

New constructs a Redis-backed idempotency store.

func (*Store) Get

Get returns an idempotency record if present.

func (*Store) Release added in v2.1.0

func (s *Store) Release(ctx context.Context, key string) error

Release removes an in-flight idempotency reservation by key.

This method preserves the v2 compatibility contract. New middleware uses ReleaseReservation when available so tokened reservations are not released by unrelated requests.

func (*Store) ReleaseReservation added in v2.1.0

func (s *Store) ReleaseReservation(ctx context.Context, key, token string) error

ReleaseReservation removes a stored idempotency reservation when token matches.

func (*Store) Save

func (s *Store) Save(ctx context.Context, key string, record ports.IdempotencyRecord, ttl time.Duration) error

Save persists a completed idempotency record.

func (*Store) TryBegin

func (s *Store) TryBegin(ctx context.Context, key string, record ports.IdempotencyRecord, ttl time.Duration) (bool, error)

TryBegin reserves a key for an in-flight request.

Jump to

Keyboard shortcuts

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