Documentation
¶
Overview ¶
Package cache persists idempotency records in Redis or Valkey.
New wraps an application-owned Client with attribute and clock Options. The resulting Store implements core Idempotency persistence and can be passed to its manager. The application owns connection setup, TLS, credentials and client shutdown.
Atomic acquisition ¶
The adapter uses atomic claim and compare-and-swap behavior to reject live records and recover expired claims. A missing or zero execution deadline does not make an otherwise unexpired claim recoverable. ConsistencyError identifies storage failures that prevent the required acquisition guarantees.
Use a shared service for coordination across Lambda environments. This module is optional and does not add Redis dependencies to the core Idempotency module.
For usage and compatibility details, see the user guide.
Index ¶
- type Client
- type ConsistencyError
- type Options
- type Store
- func (s *Store) Delete(ctx context.Context, key string) error
- func (s *Store) Get(ctx context.Context, key string) (idempotency.Record, error)
- func (s *Store) Put(ctx context.Context, record idempotency.Record, now time.Time) error
- func (s *Store) Update(ctx context.Context, record idempotency.Record) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client interface {
Get(context.Context, string) *redis.StringCmd
SetArgs(context.Context, string, any, redis.SetArgs) *redis.StatusCmd
Del(context.Context, ...string) *redis.IntCmd
Eval(context.Context, string, []string, ...any) *redis.Cmd
}
Client is implemented by go-redis standalone, Sentinel and cluster clients. The caller configures credentials, TLS, deadlines and retries, and owns Close.
type ConsistencyError ¶
type ConsistencyError struct{ Err error }
func (*ConsistencyError) Error ¶
func (e *ConsistencyError) Error() string
func (*ConsistencyError) Unwrap ¶
func (e *ConsistencyError) Unwrap() error
type Options ¶
type Options struct {
StatusAttribute, ExpiryAttribute, InProgressExpiryAttribute string
DataAttribute, ValidationAttribute string
Now func() time.Time
// OmitValidationOnSuccess reproduces the pinned TypeScript cache writer's
// omission. Leave false to retain validation when replaying completed records.
OmitValidationOnSuccess bool
}
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
func New ¶
Example ¶
This example configures a shared store. Actual operations require Redis or Valkey.
package main
import (
"github.com/rambow-cloud/powertools-lambda-go/idempotency"
"github.com/rambow-cloud/powertools-lambda-go/idempotency/cache"
"github.com/redis/go-redis/v9"
)
func main() {
client := redis.NewClient(&redis.Options{Addr: "localhost:6379"})
defer client.Close()
store, err := cache.New(client, cache.Options{})
if err != nil {
panic(err)
}
manager, err := idempotency.New(store, idempotency.Options{
KeyPrefix: "orders", EventKeyJMESPath: "orderId",
})
if err != nil {
panic(err)
}
_ = manager // Reuse the manager and wrap business operations during invocations.
}
Output: