(user_id: str, service: str)
| 120 | logger.error(f"Failed to send abuse alert: {e}") |
| 121 | |
| 122 | async def increment_usage(user_id: str, service: str) -> int: |
| 123 | r = await get_redis() |
| 124 | ttl = _seconds_until_midnight() |
| 125 | |
| 126 | # Increment rate limit counter (fixed 60s window) |
| 127 | rl_key = f"ratelimit:{user_id}" |
| 128 | rl_count = await r.incr(rl_key) |
| 129 | if rl_count == 1: |
| 130 | await r.expire(rl_key, 60) |
| 131 | |
| 132 | # Increment daily quota counter |
| 133 | quota_key = f"quota:{user_id}:{service}" |
| 134 | new_count = await r.incr(quota_key) |
| 135 | if new_count == 1: |
| 136 | await r.expire(quota_key, ttl) |
| 137 | |
| 138 | return new_count |
| 139 | |
| 140 | async def get_usage_for_service(user_id: str, service: str) -> int: |
| 141 | r = await get_redis() |
no test coverage detected