Skip to content

Instantly share code, notes, and snippets.

@PouyaEsmaeili
Last active January 3, 2023 21:43
Show Gist options
  • Save PouyaEsmaeili/fba52cc7ac80ee3f8c11190fdc7a10dc to your computer and use it in GitHub Desktop.
Save PouyaEsmaeili/fba52cc7ac80ee3f8c11190fdc7a10dc to your computer and use it in GitHub Desktop.
from datetime import timedelta
from random import choices
from redis import StrictRedis
from string import ascii_uppercase, ascii_lowercase
class RateLimiter(object):
def __init__(self,
con_pool: StrictRedis,
number_of_requests: int,
time_bound: timedelta,
limit_per_client: bool = False,
lock_timeout: float = 0.1,
log_value: str = ''):
self._con_pool = con_pool
self._number_of_requests = number_of_requests
self._time_bound = time_bound
self._limit_per_client = limit_per_client
self._lock_timeout = lock_timeout
self._log_value = log_value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment