Record an interaction from the given IP address. Uses a sliding window approach with sorted sets in Redis.
(ip: str)
| 22 | |
| 23 | |
| 24 | def record_interaction(ip: str) -> None: |
| 25 | """ |
| 26 | Record an interaction from the given IP address. |
| 27 | Uses a sliding window approach with sorted sets in Redis. |
| 28 | """ |
| 29 | key, now = _key(ip), _now_us() |
| 30 | |
| 31 | cache.zremrangebyscore(key, 0, now - WINDOW_US) |
| 32 | cache.zadd(key, {str(now): now}) |
| 33 | cache.expire(key, RATE_LIMIT_EXPIRY) |
| 34 | |
| 35 | |
| 36 | def is_blocked(ip: str) -> bool: |
nothing calls this directly
no test coverage detected
searching dependent graphs…