klock

package
v1.18.0 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2023 License: Apache-2.0 Imports: 10 Imported by: ? modules, 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.

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