apicrud.RateLimit

class apicrud.RateLimit

Rate Limiting

__init__()

Initialize self. See help(type(self)) for accurate signature.

Methods

__init__()

Initialize self.

call([service, uid])

Apply the granted rate limit for uid to a given service Two redis keys are used, for even and odd intervals as measured modulo the Unix epoch time.

call(service='*', uid=None)

Apply the granted rate limit for uid to a given service Two redis keys are used, for even and odd intervals as measured modulo the Unix epoch time. The current interval’s key is incremented if we haven’t reached the limit yet, then we delete that key at first call seen next interval and increment the other key. The keys expire within interval-1 seconds to keep the cache clear after the user stops sending calls.

Parameters
  • service (str) – name of a service

  • uid (str) – a user ID

Returns

true if limit exceeded

Return type

bool