mirror of
https://github.com/hibiken/asynq.git
synced 2025-04-23 01:00:17 +08:00
fix lua script
This commit is contained in:
parent
f7f6c93271
commit
9ce81080b2
@ -1,3 +1,4 @@
|
|||||||
|
// Package rate contains rate limiting strategies for asynq.Handler(s).
|
||||||
package rate
|
package rate
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -51,9 +52,9 @@ local count = redis.call("ZCARD", KEYS[1])
|
|||||||
|
|
||||||
if (count < tonumber(ARGV[1])) then
|
if (count < tonumber(ARGV[1])) then
|
||||||
redis.call("ZADD", KEYS[1], ARGV[3], ARGV[4])
|
redis.call("ZADD", KEYS[1], ARGV[3], ARGV[4])
|
||||||
return true
|
return 'true'
|
||||||
else
|
else
|
||||||
return false
|
return 'false'
|
||||||
end
|
end
|
||||||
`)
|
`)
|
||||||
|
|
||||||
@ -75,18 +76,13 @@ func (s *Semaphore) Acquire(ctx context.Context) (bool, error) {
|
|||||||
return false, fmt.Errorf("provided context is missing task ID value")
|
return false, fmt.Errorf("provided context is missing task ID value")
|
||||||
}
|
}
|
||||||
|
|
||||||
b, err := acquireCmd.Run(ctx, s.rc,
|
return acquireCmd.Run(ctx, s.rc,
|
||||||
[]string{semaphoreKey(s.scope)},
|
[]string{semaphoreKey(s.scope)},
|
||||||
s.maxTokens,
|
s.maxTokens,
|
||||||
time.Now().Unix(),
|
time.Now().Unix(),
|
||||||
d.Unix(),
|
d.Unix(),
|
||||||
taskID,
|
taskID,
|
||||||
).Bool()
|
).Bool()
|
||||||
if err == redis.Nil {
|
|
||||||
return b, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return b, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Release will release the token on the counting semaphore.
|
// Release will release the token on the counting semaphore.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user