<s> from __future__ import absolute_import <EOL> from time import time <EOL> from sentry . exceptions import InvalidConfiguration <EOL> from sentry . ratelimits . base import RateLimiter <EOL> from sentry . utils . redis import get_cluster_from_options <EOL> class RedisRateLimiter ( RateLimiter ) : <EOL> ttl = <NUM_LIT> <EOL> def __init__ ( self , ** options ) : <EOL> self . cluster , options = get_cluster_from_options ( '<STR_LIT>' , options ) <EOL> def validate ( self ) : <EOL> try : <EOL> with self . cluster . all ( ) as client : <EOL> client . ping ( ) <EOL> except Exception as e : <EOL> raise InvalidConfiguration ( unicode ( e ) ) <EOL> def is_limited ( self , project , key , limit ) : <EOL> key = '<STR_LIT>' % ( <EOL> key , project . id , int ( time ( ) / self . ttl ) <EOL> ) <EOL> with self . cluster . map ( ) as client : <EOL> proj_result = client . incr ( key ) <EOL> client . expire ( key , self . ttl ) <EOL> return proj_result . value > limit </s>
