<s> from cloudferry . cfglib import CONF <EOL> from cloudferry . lib . utils import log <EOL> LOG = log . getLogger ( __name__ ) <EOL> CONNECTION = [ None ] <EOL> def redis_socket_to_kwargs ( function ) : <EOL> def wrapper ( * args , ** kwargs ) : <EOL> if not CONNECTION [ <NUM_LIT:0> ] : <EOL> import redis <EOL> check_redis_config ( ) <EOL> CONNECTION [ <NUM_LIT:0> ] = redis . StrictRedis ( <EOL> host = CONF . database . host , <EOL> port = CONF . database . port ) <EOL> return function ( * args , connection = CONNECTION [ <NUM_LIT:0> ] , ** kwargs ) <EOL> return wrapper <EOL> def check_redis_config ( ) : <EOL> errors_found = False <EOL> host = CONF . database . host <EOL> port = CONF . database . port <EOL> if host is None or host == "<STR_LIT>" or not isinstance ( host , basestring ) : <EOL> message = ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> LOG . error ( message ) <EOL> errors_found = True <EOL> if ( port is None or <EOL> not isinstance ( port , basestring ) and <EOL> not isinstance ( port , int ) or port == "<STR_LIT>" ) : <EOL> message = ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> LOG . error ( message ) <EOL> errors_found = True <EOL> import redis <EOL> from redis import exceptions as redis_exceptions <EOL> try : <EOL> r = redis . StrictRedis ( host = host , port = port ) <EOL> r . ping ( ) <EOL> except redis_exceptions . RedisError as e : <EOL> LOG . error ( "<STR_LIT>" , e ) <EOL> errors_found = True <EOL> if errors_found : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> @ redis_socket_to_kwargs <EOL> def put ( key , value , connection ) : <EOL> connection . set ( key , value ) <EOL> @ redis_socket_to_kwargs <EOL> def get ( key , connection ) : <EOL> return connection . get ( key ) <EOL> @ redis_socket_to_kwargs <EOL> def delete ( key , connection ) : <EOL> return connection . delete ( key ) <EOL> @ redis_socket_to_kwargs <EOL> def delete_batch ( data_keys , connection ) : <EOL> pipe = connection . pipeline ( ) <EOL> for key in data_keys : <EOL> pipe . delete ( key ) <EOL> pipe . execute ( ) <EOL> @ redis_socket_to_kwargs <EOL> def keys ( pattern , connection ) : <EOL> return connection . keys ( pattern ) </s>
