storages

package
v0.0.0-...-c7901e9 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2026 License: MIT Imports: 1 Imported by: 0

README

storages

import "github.com/altessa-s/go-atlas/data/idempotency/storages"

Package storages defines the Storage interface for idempotency key persistence. Implementations live in subpackages and are injected into the top-level idempotency.Keeper to supply the underlying storage backend.

Key types

Type / Interface Description
Storage Interface: AttemptLock, Complete, Delete
Status Key state: StatusInProgress, StatusSuccess
State Holds the current status and optional response data for a key

Subpackages

Package Description
memory In-memory backend with TTL
nats NATS JetStream storage
redis Distributed Redis storage

Documentation

Overview

Package storages defines the Storage interface for idempotency key persistence. Implementations are in subpackages: memory, redis, nats.

Example:

var store storages.Storage = redis.New(client)
store.Add(ctx, "request-123")

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type State

type State struct {
	Status Status `json:"status"`
	Data   any    `json:"data,omitempty"`
}

State holds the current status and metadata of an idempotency key.

type Status

type Status string

Status represents the state of an idempotency key.

const (
	// StatusInProgress indicates the request is currently being processed.
	StatusInProgress Status = "IN_PROGRESS"
	// StatusSuccess indicates the request was completed successfully.
	StatusSuccess Status = "SUCCESS"
)

type Storage

type Storage interface {
	// AttemptLock tries to acquire a lock for the given key.
	// It operates atomically:
	// - If key does not exist: Sets key to val and returns (true, nil, nil).
	// - If key exists: Returns (false, existingVal, nil).
	AttemptLock(ctx context.Context, key string, val []byte) (bool, []byte, error)

	// Complete marks the idempotency key as completed by updating its value.
	// It overwrites the existing value with val.
	Complete(ctx context.Context, key string, val []byte) error

	// Delete removes the key from storage (e.g. on failure).
	Delete(ctx context.Context, key string) error
}

Storage interface for idempotency key storage.

Directories

Path Synopsis
Package memory provides in-memory storage for idempotency keys with TTL support.
Package memory provides in-memory storage for idempotency keys with TTL support.
Package nats provides NATS JetStream KeyValue storage for idempotency keys.
Package nats provides NATS JetStream KeyValue storage for idempotency keys.
Package redis provides Redis storage for idempotency keys with TTL support.
Package redis provides Redis storage for idempotency keys with TTL support.

Jump to

Keyboard shortcuts

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