Mutex

package module
v0.0.0-...-9f060c8 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2023 License: Apache-2.0 Imports: 0 Imported by: 0

README

go-lock

distributed lock

Introduce

The design style is similar to the low-level locking mechanism of Golang, which allows developers to easily migrate to the use of distributed locks, use hierarchical sleep mechanisms to prevent hunger in extreme states, and use a rollback mechanism at the user level to ensure the effectiveness of the locking mechanism

the distributed lock configuration is global,and it will task less memory space

Warning

Currently, only Redis standalone machines are supported

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssemblyMutex

func AssemblyMutex(options ...ConfigOption)

AssemblyMutex the mutex config init

Types

type ConfigOption

type ConfigOption func(*config)

func WithCancelTime

func WithCancelTime(cancelTime time.Duration) ConfigOption

WithCancelTime a time for redis conn need spend the max time

func WithExpiresTime

func WithExpiresTime(expireTime time.Duration) ConfigOption

WithExpiresTime Duration of lock

func WithMaxOffsetTime

func WithMaxOffsetTime(maxOffsetTime time.Duration) ConfigOption

WithMaxOffsetTime be set to priority about the max gradient times for the interval of requesting lock

func WithReties

func WithReties(reties int32) ConfigOption

WithReties be set to priority about the gradient decreases for the interval of requesting lock,After how many repetitions

func WithStorageClient

func WithStorageClient(client *redis.Client) ConfigOption

WithStorageClient the must be init

type Mutex

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

func NewMutex

func NewMutex(name string) *Mutex

func (*Mutex) Discard

func (mutex *Mutex) Discard() bool

TODO is discard is true, this represent the distribted lock is failed in the progress

func (*Mutex) Lock

func (mutex *Mutex) Lock()

func (*Mutex) TryLock

func (mutex *Mutex) TryLock() bool

func (*Mutex) UnLock

func (mutex *Mutex) UnLock()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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