<s> from redis_cache . compat import DEFAULT_TIMEOUT <EOL> try : <EOL> import cPickle as pickle <EOL> except ImportError : <EOL> import pickle <EOL> import random <EOL> from redis_cache . backends . base import BaseRedisCache <EOL> class RedisCache ( BaseRedisCache ) : <EOL> def __init__ ( self , server , params ) : <EOL> """<STR_LIT>""" <EOL> super ( RedisCache , self ) . __init__ ( server , params ) <EOL> for server in self . servers : <EOL> client = self . create_client ( server ) <EOL> self . clients [ client . connection_pool . connection_identifier ] = client <EOL> self . client_list = self . clients . values ( ) <EOL> self . master_client = self . get_master_client ( ) <EOL> def get_client ( self , key , write = False ) : <EOL> if write and self . master_client is not None : <EOL> return self . master_client <EOL> return random . choice ( list ( self . client_list ) ) <EOL> def delete_many ( self , keys , version = None ) : <EOL> """<STR_LIT>""" <EOL> versioned_keys = self . make_keys ( keys , version = version ) <EOL> if versioned_keys : <EOL> self . _delete_many ( self . master_client , versioned_keys ) <EOL> def clear ( self , version = None ) : <EOL> """<STR_LIT>""" <EOL> if version is None : <EOL> self . _clear ( self . master_client ) <EOL> else : <EOL> self . delete_pattern ( '<STR_LIT:*>' , version = version ) <EOL> def get_many ( self , keys , version = None ) : <EOL> versioned_keys = self . make_keys ( keys , version = version ) <EOL> return self . _get_many ( self . master_client , keys , versioned_keys = versioned_keys ) <EOL> def set_many ( self , data , timeout = DEFAULT_TIMEOUT , version = None ) : <EOL> """<STR_LIT>""" <EOL> timeout = self . get_timeout ( timeout ) <EOL> versioned_keys = self . make_keys ( data . keys ( ) , version = version ) <EOL> if timeout is None : <EOL> new_data = { } <EOL> for key in versioned_keys : <EOL> new_data [ key ] = self . prep_value ( data [ key . _original_key ] ) <EOL> return self . _set_many ( self . master_client , new_data ) <EOL> pipeline = self . master_client . pipeline ( ) <EOL> for key in versioned_keys : <EOL> value = self . prep_value ( data [ key . _original_key ] ) <EOL> self . _set ( pipeline , key , value , timeout ) <EOL> pipeline . execute ( ) <EOL> def incr_version ( self , key , delta = <NUM_LIT:1> , version = None ) : <EOL> """<STR_LIT>""" <EOL> if version is None : <EOL> version = self . version <EOL> old = self . make_key ( key , version ) <EOL> new = self . make_key ( key , version = version + delta ) <EOL> return self . _incr_version ( self . master_client , old , new , delta , version ) <EOL> def delete_pattern ( self , pattern , version = None ) : <EOL> pattern = self . make_key ( pattern , version = version ) <EOL> self . _delete_pattern ( self . master_client , pattern ) <EOL> def reinsert_keys ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _reinsert_keys ( self . master_client ) </s>
