Remove Redis dependency from RateLimiterWrapper
- Always use ETS-based RateLimiter instead of checking for REDIS_URL - Remove RedisRateLimiter calls that were causing crashes - Simplify wrapper to only delegate to Aprsme.RateLimiter
This commit is contained in:
parent
ae14b120fa
commit
571814c080
2 changed files with 15 additions and 27 deletions
|
|
@ -61,4 +61,8 @@ This is a web application written using the Phoenix web framework.
|
|||
- Use `Task.async_stream(collection, callback, options)` for concurrent enumeration with back-pressure. The majority of times you will want to pass `timeout: :infinity` as option
|
||||
- **Always run mix format after changing any Elixir files**
|
||||
|
||||
[... rest of the file remains unchanged ...]
|
||||
## Git Commit Guidelines
|
||||
|
||||
- **Never** add "Co-Authored-By: Claude" or similar AI co-authorship tags to commits
|
||||
- Commits should appear as authored solely by the user (Graham)
|
||||
- Keep commit messages clear and concise, describing what changed and why
|
||||
|
|
@ -1,46 +1,30 @@
|
|||
defmodule Aprsme.RateLimiterWrapper do
|
||||
@moduledoc """
|
||||
Wrapper that provides the same API for both Hammer and RedisRateLimiter
|
||||
Wrapper that provides the same API using ETS-based rate limiter
|
||||
"""
|
||||
|
||||
@doc """
|
||||
Check rate limit - compatible with Hammer.hit/3 API
|
||||
"""
|
||||
def hit(bucket, scale_ms, limit) do
|
||||
if using_redis?() do
|
||||
Aprsme.RedisRateLimiter.check_rate(bucket, limit, scale_ms)
|
||||
else
|
||||
Aprsme.RateLimiter.hit(bucket, scale_ms, limit)
|
||||
end
|
||||
Aprsme.RateLimiter.hit(bucket, scale_ms, limit)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Reset rate limit for a bucket
|
||||
"""
|
||||
def reset(bucket) do
|
||||
if using_redis?() do
|
||||
Aprsme.RedisRateLimiter.reset(bucket)
|
||||
else
|
||||
# Hammer doesn't provide a reset function
|
||||
# Best we can do is return ok
|
||||
:ok
|
||||
end
|
||||
def reset(_bucket) do
|
||||
# ETS-based rate limiter doesn't provide a reset function
|
||||
# Return ok
|
||||
:ok
|
||||
end
|
||||
|
||||
@doc """
|
||||
Get current count for a bucket
|
||||
"""
|
||||
def count(bucket, scale_ms) do
|
||||
if using_redis?() do
|
||||
Aprsme.RedisRateLimiter.count(bucket, scale_ms)
|
||||
else
|
||||
# Hammer doesn't provide a count function
|
||||
# Return 0 as default
|
||||
{:ok, 0}
|
||||
end
|
||||
end
|
||||
|
||||
defp using_redis? do
|
||||
System.get_env("REDIS_URL") != nil
|
||||
def count(_bucket, _scale_ms) do
|
||||
# ETS-based rate limiter doesn't provide a count function
|
||||
# Return 0 as default
|
||||
{:ok, 0}
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue