chore: coding style (#4082)

This commit is contained in:
Kevin Wan
2024-04-17 23:37:35 +08:00
committed by GitHub
parent 62c88a84d1
commit e9dc96af17
10 changed files with 24 additions and 30 deletions

View File

@@ -2,4 +2,4 @@ if redis.call("GET", KEYS[1]) == ARGV[1] then
return redis.call("DEL", KEYS[1])
else
return 0
end
end

View File

@@ -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

View File

@@ -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
}