mirror of https://github.com/interlegis/sapl.git
Browse Source
Each tenant now uses one HASH per period (daily/weekly) with the IP as the field, instead of one STRING key per IP per period. Memory impact at 1,200 tenants / 500k unique IPs/day: STRING: ~444 MB → HASH: ~190 MB (57% reduction, ~254 MB saved) Global keyspace: ~3,000,000 STRING keys → 2,400 HASH keys - Add QUOTA_DAILY_HASH / QUOTA_WEEKLY_HASH constants (no :ip: suffix) - Add _HINCRBY_LUA: HINCRBY + conditional EXPIRE on hash creation - Add _hincrby_with_ttl(hash_key, field, ttl); fallback uses composite string key hash_key:field when Redis is unavailable - Update _check_api_quota to call _hincrby_with_ttl with HASH keys - Remove QUOTA_IP_DAILY / QUOTA_IP_WEEKLY (replaced by HASH constants) - Update tests: patch _hincrby_with_ttl; add weekly quota and HASH key routing tests - Update RATE-LIMITER-PLAN.md key schema table Migration: old quota:*:ip:* STRING keys expire naturally within 7 days. To reclaim memory immediately after deploy: redis-cli -n 1 --scan --pattern 'quota:*:ip:*' | xargs -L 100 redis-cli -n 1 DEL Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>rate-limiter-2026
3 changed files with 97 additions and 16 deletions
Loading…
Reference in new issue