#NEWLINE# @ log_on_error #NEWLINE# def post_redis( channel , data , path ) : #NEWLINE# #INDENT# digits = re . findall ( '(\\d+)' , path ) #NEWLINE# if digits : #NEWLINE# #INDENT# count = ( int ( digits [ ( - 1 ) ] ) % REDIS_SAMPLE_RATE ) #NEWLINE# if ( count != 0 ) : #NEWLINE# #INDENT# logger . debug ( 'Image {} not sampled ({}/{}).' . format ( path , count , REDIS_SAMPLE_RATE ) ) #NEWLINE# return #NEWLINE# #UNINDENT# #UNINDENT# for redis_host in [ h for h in redis_hosts if h ] : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# r = redis . StrictRedis ( host = redis_host , port = REDIS_PORT , db = REDIS_DB , password = REDIS_PASSWORD ) #NEWLINE# channel_ttl = r . get ( ( ( 'thumb/' + channel ) + '/ttl' ) ) #NEWLINE# channel_ttl = ( int ( channel_ttl ) if channel_ttl else REDIS_TTL ) #NEWLINE# key = ( 'thumb/' + channel ) #NEWLINE# blob_key = ( 'blob/' + str ( uuid . uuid4 ( ) ) ) #NEWLINE# timestamp = os . path . getmtime ( path ) #NEWLINE# utctimestamp = int ( time . mktime ( datetime . datetime . utcfromtimestamp ( timestamp ) . timetuple ( ) ) ) #NEWLINE# r . zadd ( key , utctimestamp , blob_key ) #NEWLINE# r . setex ( blob_key , channel_ttl , data ) #NEWLINE# r . zremrangebyscore ( key , '-inf' , ( utctimestamp - channel_ttl ) ) #NEWLINE# logger . debug ( 'Pushed {} to {}. Key={}, utctimestamp={}' . format ( path , redis_host , blob_key , utctimestamp ) ) #NEWLINE# #UNINDENT# except Exception as err : #NEWLINE# #INDENT# logger . error ( err )