klock

package
v2.3.1 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CreateTimeKey = "create_time"
)

Variables

View Source
var (
	ErrNotInit            = errors.New("klock not init")
	ErrCreateLockTimeout  = errors.New("create lock timeout")
	ErrCreateLockMaxRetry = errors.New("create lock reached max attempts")
	ErrUnlockMaxRetry     = errors.New("unlock reached max attempts")
	ErrLockExist          = errors.New("lock exist")
)
View Source
var (
	DefaultTTL                  = 60 * time.Second
	DefaultTimeout              = 3 * time.Second
	DefaultTryLockRetryInterval = 1 * time.Second
	DefaultLockRetryInterval    = 1 * time.Second
)

Functions

func Init

func Init(namespace string) error

func Lock

func Lock(key string)

Lock will block until the lock is acquired

func LockWithRetry

func LockWithRetry(key string, retry int) error

func TryLock

func TryLock(key string) error

TryLock will try to acquire the lock, if the lock is already acquired, it will return ErrLockExist Timeout is set to 3 seconds

func Unlock

func Unlock(key string) error

func UnlockWithRetry

func UnlockWithRetry(key string, retry int) error

Types

type Client

type Client struct {
	client.Client
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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