mutex

package
v0.0.0-...-3b218eb Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotAcquireLock = errors.New("failed t acquire lock")
)

Functions

This section is empty.

Types

type DefaultLock

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

func (*DefaultLock) Lock

func (d *DefaultLock) Lock(_ string) error

Lock implements Locker.

func (*DefaultLock) Unlock

func (d *DefaultLock) Unlock(key string) error

Unlock implements Locker.

type EtcdConfig

type EtcdConfig struct {
	Timeout   time.Duration // do handle expired time duration
	Endpoints []string
}

type EtcdMutex

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

func (*EtcdMutex) Lock

func (e *EtcdMutex) Lock(key string) error

Lock implements Locker.

func (*EtcdMutex) Unlock

func (e *EtcdMutex) Unlock(key string) error

Unlock implements Locker.

type Locker

type Locker interface {
	Lock(key string) error
	Unlock(key string) error
}

func NewEtcdMutex

func NewEtcdMutex(ctx context.Context, cfg EtcdConfig) (Locker, error)

func NewRedisMutex

func NewRedisMutex(ctx context.Context, cfg *RedisConfig) (Locker, error)

func NewRedisMutexWithClient

func NewRedisMutexWithClient(client *redis.Client) (Locker, error)

type RedisConfig

type RedisConfig struct {
	Addr     string
	Username string
	Password string
	DB       int
}

type RedisMutex

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

func (*RedisMutex) Lock

func (r *RedisMutex) Lock(key string) error

Lock implements Locker.

func (*RedisMutex) Unlock

func (r *RedisMutex) Unlock(key string) error

Unlock implements Locker.

Jump to

Keyboard shortcuts

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