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~ Expand ▾ Collapse ▴ Documentation ¶ Index ¶ type RedisLock func NewRedisLock(store *red.Client, key string) *RedisLock func (rl *RedisLock) Acquire() (bool, error) func (rl *RedisLock) Release() (bool, error) func (rl *RedisLock) SetExpire(seconds int) 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. Source Files ¶ View all Source files lock.go Click to show internal directories. Click to hide internal directories.