redis_lock

package
v0.0.0-...-e20221d Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFailedToPreemptLock = errors.New("redis-lock: 抢锁失败")
)
View Source
var (
	ErrLockNotHold = errors.New("redis-lock: 你没有持有锁")
)

Functions

This section is empty.

Types

type Client

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

func (*Client) Lock

func (c *Client) Lock(ctx context.Context, key string, expiration, timeout time.Duration, retry RetryStrategy) (*Lock, error)

func (*Client) SingleFlightLock

func (c *Client) SingleFlightLock(ctx context.Context, key string, expiration, timeout time.Duration, retry RetryStrategy) (*Lock, error)

SingleFlightLock 用SingleFlight防止缓存击穿

func (*Client) TryLock

func (c *Client) TryLock(ctx context.Context, key string, expiration time.Duration) (*Lock, error)

type ClientV2

type ClientV2 struct {
	Client
	// contains filtered or unexported fields
}

func (*ClientV2) LockLock

func (c *ClientV2) LockLock(ctx context.Context, key string, expiration, timeout time.Duration, retry RetryStrategy) (*Lock, error)

LockLock 用上锁方式防止缓存击穿

type FixedIntervalRetryStrategy

type FixedIntervalRetryStrategy struct {
	Interval time.Duration
	MaxCnt   int
	// contains filtered or unexported fields
}

func (*FixedIntervalRetryStrategy) Next

type Lock

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

func NewLock

func NewLock(client redis.Cmdable, key, value string, expiration time.Duration) *Lock

func (*Lock) AutoRefresh

func (l *Lock) AutoRefresh(interval time.Duration, timeout time.Duration) error

func (*Lock) Refresh

func (l *Lock) Refresh(ctx context.Context) error

func (*Lock) Unlock

func (l *Lock) Unlock(ctx context.Context) error

type RetryStrategy

type RetryStrategy interface {
	// Next 返回重试的时间间隔,和要不要继续重试
	Next() (time.Duration, bool)
}

Jump to

Keyboard shortcuts

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