Categorygithub.com/go-cinch/common/idempotent
modulepackage
1.0.4
Repository: https://github.com/go-cinch/common.git
Documentation: pkg.go.dev

# README

Idempotent

api idempotent tool based on redis lua script.

Usage

go get -u github.com/go-cinch/common/idempotent
import (
	"context"
	"fmt"
	"github.com/go-cinch/common/idempotent"
	"github.com/redis/go-redis/v9"
)

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

# Functions

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

No description provided by the author
No description provided by the author