Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion RateLimit.Redis/Decepticon.RateLimit.Redis.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Donate via Paypal: dekcodeofficial@gmail.com</Description>
<PackageIcon>icon.png</PackageIcon>
<PackageReleaseNotes></PackageReleaseNotes>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<Version>1.0.0</Version>
<Version>1.1.0</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion RateLimit.Redis/Helpers/DateTimeHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal static class DateTimeHelpers
public static DateTime UnixTimeStampToDateTime(double unixTimeStampInSeconds)
{
// Unix timestamp is seconds past epoch
return _Epoch.AddSeconds(unixTimeStampInSeconds).ToLocalTime();
return _Epoch.AddSeconds(unixTimeStampInSeconds).ToUniversalTime();
}
}
}
8 changes: 6 additions & 2 deletions RateLimit.Redis/RateLimiter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ public ThrottleRateLimitResult Validate(ThrottleRateLimitRequest request)
local count = tonumber(ARGV[3])
local ticks = currentTimeTicks
local result = 1
local ttl = 86400

-- Try getting tracking config from existing record
local countStr = redis.call('GET', KEYS[1])
Expand Down Expand Up @@ -206,15 +207,18 @@ public ThrottleRateLimitResult Validate(ThrottleRateLimitRequest request)

-- Consume a token
count = count - 1

-- Get seconds for a complete refill, and then add 1hr to prevent deleting keys too frequently
ttl = (capacity / refillRate) + 3600

-- Determine the outcome
if count < 0 then
result = 0
count = 0
end

redis.call('SET', KEYS[1], count)
redis.call('SET', KEYS[2], ticks)
redis.call('SET', KEYS[1], count, 'EX', ttl)
redis.call('SET', KEYS[2], ticks, 'EX', ttl)

return result .. ',' .. math.abs(10000000 / refillRate)
";
Expand Down