idempotent

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2025 License: MIT Imports: 6 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Idempotent

api idempotent tool based on redis lua script.

Usage

go get -u github.com/onexstack/onex/pkg/idempotent
import (
	"context"
	"fmt"
	"github.com/redis/go-redis/v9"
  "github.com/onexstack/onex/pkg/idempotent"
)

func main() {
	client := redis.NewClient(&redis.Options{
		Addr: "127.0.0.1:6379",
		DB:   0,
	})
	i := idempotent.New(
		idempotent.WithRedis(client),
	)

	token := i.Token(context.Background())
	fmt.Println(i.Check(context.Background(), token))
	// true

	// second check will fail
	fmt.Println(i.Check(context.Background(), token))
	// false
}

Options

  • WithRedis - redis client, default 127.0.0.1:6379
  • WithPrefix - cache key prefix, default idempotent
  • WithExpire - key expire time, default 60 minute

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithExpire

func WithExpire(min int) func(*Options)

func WithPrefix

func WithPrefix(prefix string) func(*Options)

func WithRedis

func WithRedis(rd redis.UniversalClient) func(*Options)

Types

type Idempotent

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

func New

func New(options ...func(*Options)) *Idempotent

func (*Idempotent) Check

func (i *Idempotent) Check(ctx context.Context, token string) bool

func (*Idempotent) Token

func (i *Idempotent) Token(ctx context.Context) string

type Options

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

Jump to

Keyboard shortcuts

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