store

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package store provides the idempotency store interface and its NoOp implementation. Redis implementation is deferred to v0.4. It does not own connection management. Primary dependency: context for request-scoped operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IdempotencyStore

type IdempotencyStore interface {
	// Get retrieves a cached response for key.
	// Returns (value, true, nil) on hit.
	// Returns (nil, false, nil) on miss (redis.Nil maps to this).
	// Returns (nil, false, err) on store error.
	Get(ctx context.Context, key string) ([]byte, bool, error)

	// SetNX stores value at key if and only if the key does not already exist.
	// The TTL is determined by the store implementation's construction-time config.
	// Returns (true, nil) if the key was written.
	// Returns (false, nil) if the key already existed — concurrent write, not an error.
	// Returns (false, err) on store error.
	SetNX(ctx context.Context, key string, value []byte) (bool, error)
}

IdempotencyStore is the persistence layer for request deduplication. Implementations must be safe for concurrent use. TTL-based expiry handles cleanup — no explicit delete method.

type NoOpIdempotencyStore

type NoOpIdempotencyStore struct{}

NoOpIdempotencyStore is a no-operation IdempotencyStore. Get always returns a miss. SetNX always returns (true, nil). Used in tests and as the pre-v0.4 stub.

func NewNoOpIdempotencyStore

func NewNoOpIdempotencyStore() *NoOpIdempotencyStore

NewNoOpIdempotencyStore returns a new NoOpIdempotencyStore.

func (*NoOpIdempotencyStore) Get

func (n *NoOpIdempotencyStore) Get(ctx context.Context, key string) ([]byte, bool, error)

Get returns (nil, false, nil) for all inputs — always a miss.

func (*NoOpIdempotencyStore) SetNX

func (n *NoOpIdempotencyStore) SetNX(ctx context.Context, key string, value []byte) (bool, error)

SetNX returns (true, nil) for all inputs — always signals "written successfully".

type RedisIdempotencyStore added in v0.4.0

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

RedisIdempotencyStore is a Redis-backed IdempotencyStore. TTL is fixed at construction time and applied on every SetNX call. All methods are safe for concurrent use.

func NewRedisIdempotencyStore added in v0.4.0

func NewRedisIdempotencyStore(client redis.UniversalClient, ttl time.Duration) *RedisIdempotencyStore

NewRedisIdempotencyStore returns a new RedisIdempotencyStore using client with the given ttl.

func (*RedisIdempotencyStore) Get added in v0.4.0

func (s *RedisIdempotencyStore) Get(ctx context.Context, key string) ([]byte, bool, error)

Get retrieves a cached response for key. Returns (value, true, nil) on hit. Returns (nil, false, nil) on miss — redis.Nil is not treated as an error. Returns (nil, false, err) on store error.

func (*RedisIdempotencyStore) SetNX added in v0.4.0

func (s *RedisIdempotencyStore) SetNX(ctx context.Context, key string, value []byte) (bool, error)

SetNX stores value at key if and only if the key does not already exist. The TTL configured at construction is applied. Returns (true, nil) if the key was written. Returns (false, nil) if the key already existed — concurrent write, not an error. Returns (false, err) on store error.

Jump to

Keyboard shortcuts

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