mirror of
https://github.com/zeromicro/go-zero.git
synced 2026-05-13 18:00:00 +08:00
chore: coding style (#4082)
This commit is contained in:
@@ -2,4 +2,4 @@ if redis.call("GET", KEYS[1]) == ARGV[1] then
|
||||
return redis.call("DEL", KEYS[1])
|
||||
else
|
||||
return 0
|
||||
end
|
||||
end
|
||||
@@ -3,4 +3,4 @@ if redis.call("GET", KEYS[1]) == ARGV[1] then
|
||||
return "OK"
|
||||
else
|
||||
return redis.call("SET", KEYS[1], ARGV[1], "NX", "PX", ARGV[2])
|
||||
end
|
||||
end
|
||||
@@ -22,14 +22,12 @@ const (
|
||||
|
||||
var (
|
||||
//go:embed lockscript.lua
|
||||
lockScript string
|
||||
|
||||
scriptLock = NewScript(lockScript)
|
||||
lockLuaScript string
|
||||
lockScript = NewScript(lockLuaScript)
|
||||
|
||||
//go:embed delscript.lua
|
||||
delScript string
|
||||
|
||||
scriptDel = NewScript(delScript)
|
||||
delLuaScript string
|
||||
delScript = NewScript(delLuaScript)
|
||||
)
|
||||
|
||||
// A RedisLock is a redis lock.
|
||||
@@ -61,7 +59,7 @@ func (rl *RedisLock) Acquire() (bool, error) {
|
||||
// AcquireCtx acquires the lock with the given ctx.
|
||||
func (rl *RedisLock) AcquireCtx(ctx context.Context) (bool, error) {
|
||||
seconds := atomic.LoadUint32(&rl.seconds)
|
||||
resp, err := rl.store.ScriptRunCtx(ctx, scriptLock, []string{rl.key}, []string{
|
||||
resp, err := rl.store.ScriptRunCtx(ctx, lockScript, []string{rl.key}, []string{
|
||||
rl.id, strconv.Itoa(int(seconds)*millisPerSecond + tolerance),
|
||||
})
|
||||
if errors.Is(err, red.Nil) {
|
||||
@@ -89,7 +87,7 @@ func (rl *RedisLock) Release() (bool, error) {
|
||||
|
||||
// ReleaseCtx releases the lock with the given ctx.
|
||||
func (rl *RedisLock) ReleaseCtx(ctx context.Context) (bool, error) {
|
||||
resp, err := rl.store.ScriptRunCtx(ctx, scriptDel, []string{rl.key}, []string{rl.id})
|
||||
resp, err := rl.store.ScriptRunCtx(ctx, delScript, []string{rl.key}, []string{rl.id})
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user