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.
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
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
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.