idempotent

package module
v0.0.0-...-c5fba85 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2022 License: MIT Imports: 6 Imported by: 0

README

Idempotent

Test

Go idempotent library

GORM Drive

db := NewDB("root:@tcp(localhost:3306)/test?parseTime=true&loc=Asia%2FShanghai&charset=utf8mb4")
i, err := idempotent.New(drive_gorm.New(db))
if err != nil {
    panic(err)
}
_ = db.Transaction(func(tx *gorm.DB) error {
    ok := i.Acquire("idempotent_key", drive_gorm.New(tx), idempotent.WithTTL(time.Minute))
    if !ok {
        fmt.Println("Repeated")
        return nil
    }
    // Some of your code
    fmt.Println("Hello")
    return nil
})

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// key过期时间
	TTL time.Duration
	//清除过期间隔
	ClearExpiryDuration time.Duration
}

func DefaultConfig

func DefaultConfig() *Config

type ConfigOpt

type ConfigOpt func(op *Config)

func WithClearExpiry

func WithClearExpiry(duration time.Duration) ConfigOpt

WithClearExpiry

func WithTTL

func WithTTL(ttl time.Duration) ConfigOpt

WithTTL

type Idempotent

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

func New

func New(d drive.Drive, opts ...ConfigOpt) (*Idempotent, error)

func (*Idempotent) Acquire

func (i *Idempotent) Acquire(key string, engine drive.Drive, opts ...ConfigOpt) bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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