lock

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: May 14, 2022 License: Apache-2.0 Imports: 5 Imported by: 1

Documentation

Overview

Package lock 一个基于 redis 的分布式锁实现。

Index

Constants

This section is empty.

Variables

View Source
var ErrorNotOk = errors.New("redis write not ok")

ErrorNotOk redis 写失败

Functions

This section is empty.

Types

type Lock

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

Lock 一个基于redis的锁实现

func New

func New(key, value string, client *redis.Client) *Lock

New 创建一个锁

func (*Lock) Lock

func (l *Lock) Lock(ctx context.Context, expire time.Duration) error

Lock 加锁

func (*Lock) Release

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

Release 释放锁

func (*Lock) Renew

func (l *Lock) Renew(ctx context.Context, expire time.Duration) error

Renew 续期锁

func (*Lock) StartRenew

func (l *Lock) StartRenew(ctx context.Context, expire time.Duration)

StartRenew 开始续期任务,需要放到 goroutine 中执行

func (*Lock) StopRenew

func (l *Lock) StopRenew()

StopRenew 停掉续期

Jump to

Keyboard shortcuts

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