getRateLimitTTL.lua 365 B

1234567891011121314151617
  1. --[[
  2. Function to get current rate limit ttl.
  3. ]]
  4. local function getRateLimitTTL(maxJobs, rateLimiterKey)
  5. if maxJobs and maxJobs <= tonumber(rcall("GET", rateLimiterKey) or 0) then
  6. local pttl = rcall("PTTL", rateLimiterKey)
  7. if pttl == 0 then
  8. rcall("DEL", rateLimiterKey)
  9. end
  10. if pttl > 0 then
  11. return pttl
  12. end
  13. end
  14. return 0
  15. end