redislock

package module
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2022 License: MIT Imports: 8 Imported by: 0

README

github.com/randolphcyg/redislock

1. install

go get github.com/randolphcyg/wework

2. Usage

初始化传入redis/v8的redisClient

...
lock = redisLock.NewRedisLock(ctx.RedisClient, redisLockKey)
// 设置过期时间
lock.SetExpire(30)
if ok, err := lock.Acquire(); !ok || err != nil {
return nil, errors.New("当前有其他用户正在进行操作,请稍后重试!")
}
...

Demo can be found in lock_test.go file~

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RedisLock

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

A RedisLock is a redis lock.

func NewRedisLock

func NewRedisLock(store *red.Client, key string) *RedisLock

NewRedisLock returns a RedisLock.

func (*RedisLock) Acquire

func (rl *RedisLock) Acquire() (bool, error)

Acquire acquires the lock.

func (*RedisLock) Release

func (rl *RedisLock) Release() (bool, error)

Release releases the lock.

func (*RedisLock) SetExpire

func (rl *RedisLock) SetExpire(seconds int)

SetExpire sets the expiration.

Jump to

Keyboard shortcuts

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