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:
Graham McIntire 2025-10-25 09:44:44 -05:00
parent ae14b120fa
commit 571814c080
No known key found for this signature in database
2 changed files with 15 additions and 27 deletions

View file

@ -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 - 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** - **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

View file

@ -1,46 +1,30 @@
defmodule Aprsme.RateLimiterWrapper do defmodule Aprsme.RateLimiterWrapper do
@moduledoc """ @moduledoc """
Wrapper that provides the same API for both Hammer and RedisRateLimiter Wrapper that provides the same API using ETS-based rate limiter
""" """
@doc """ @doc """
Check rate limit - compatible with Hammer.hit/3 API Check rate limit - compatible with Hammer.hit/3 API
""" """
def hit(bucket, scale_ms, limit) do def hit(bucket, scale_ms, limit) do
if using_redis?() do Aprsme.RateLimiter.hit(bucket, scale_ms, limit)
Aprsme.RedisRateLimiter.check_rate(bucket, limit, scale_ms)
else
Aprsme.RateLimiter.hit(bucket, scale_ms, limit)
end
end end
@doc """ @doc """
Reset rate limit for a bucket Reset rate limit for a bucket
""" """
def reset(bucket) do def reset(_bucket) do
if using_redis?() do # ETS-based rate limiter doesn't provide a reset function
Aprsme.RedisRateLimiter.reset(bucket) # Return ok
else :ok
# Hammer doesn't provide a reset function
# Best we can do is return ok
:ok
end
end end
@doc """ @doc """
Get current count for a bucket Get current count for a bucket
""" """
def count(bucket, scale_ms) do def count(_bucket, _scale_ms) do
if using_redis?() do # ETS-based rate limiter doesn't provide a count function
Aprsme.RedisRateLimiter.count(bucket, scale_ms) # Return 0 as default
else {:ok, 0}
# 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
end end
end end