go-redis / redis_rate

Rate limiting for go-redis
https://redis.uptrace.dev/guide/go-redis-rate-limiting.html
BSD 2-Clause "Simplified" License
824 stars 102 forks source link

questions about allown and allownMost #68

Open LetLifeStop opened 2 years ago

LetLifeStop commented 2 years ago

Q1: why does the code in function allown:

if remaining < 0 then
  local reset_after = tat - now
  local retry_after = diff * -1
  return {
    0, -- allowed
    0, -- remaining
    tostring(retry_after),
    tostring(reset_after),
  }
end

the remaining less zero? It should not be less than one when it should prompt that the current request cannot be precessed? like in function allownMost:

if remaining < 1 then
  local reset_after = tat - now
  local retry_after = emission_interval - diff
  return {
    0, -- allowed
    0, -- remaining
    tostring(retry_after),
    tostring(reset_after),
  }
end

Q: I can not understand the specific difference between these two function? can you explain in more detail? thank you~