redisLock

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2021 License: MIT Imports: 5 Imported by: 0

README

redisLock

基于Redis的分布式锁

Installation
go get -u "github.com/fupenglin/redisLock"
Example
lock := redisLock.New(rdb, "key")
if ok, _ := lock.Lock(ctx); !ok {
	// lock fail
	return
} 
defer lock.Unlock()
// Do something with the user.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RLocker

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

func New

func New(rdb *redis.Client, key string) *RLocker

func (*RLocker) Expand

func (rl *RLocker) Expand(ctx context.Context) (bool, error)

func (*RLocker) Lock

func (rl *RLocker) Lock(ctx context.Context) (ok bool, err error)

func (*RLocker) SetExpiration

func (rl *RLocker) SetExpiration(expiry time.Duration)

func (*RLocker) TryLock

func (rl *RLocker) TryLock(ctx context.Context, retry int) (ok bool, err error)

func (*RLocker) Unlock

func (rl *RLocker) Unlock(ctx context.Context)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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