<s> '''<STR_LIT>''' <EOL> from __future__ import absolute_import <EOL> from salt . ext . six . moves import zip <EOL> try : <EOL> import redis <EOL> HAS_REDIS = True <EOL> except ImportError : <EOL> HAS_REDIS = False <EOL> __virtualname__ = '<STR_LIT>' <EOL> def __virtual__ ( ) : <EOL> '''<STR_LIT>''' <EOL> if HAS_REDIS : <EOL> return __virtualname__ <EOL> else : <EOL> return ( False , '<STR_LIT>' ) <EOL> def _connect ( host = None , port = None , db = None , password = None ) : <EOL> '''<STR_LIT>''' <EOL> if not host : <EOL> host = __salt__ [ '<STR_LIT>' ] ( '<STR_LIT>' ) <EOL> if not port : <EOL> port = __salt__ [ '<STR_LIT>' ] ( '<STR_LIT>' ) <EOL> if not db : <EOL> db = __salt__ [ '<STR_LIT>' ] ( '<STR_LIT>' ) <EOL> if not password : <EOL> password = __salt__ [ '<STR_LIT>' ] ( '<STR_LIT>' ) <EOL> return redis . StrictRedis ( host , port , db , password ) <EOL> def _sconnect ( host = None , port = None , password = None ) : <EOL> '''<STR_LIT>''' <EOL> if host is None : <EOL> host = __salt__ [ '<STR_LIT>' ] ( '<STR_LIT>' , '<STR_LIT:localhost>' ) <EOL> if port is None : <EOL> port = __salt__ [ '<STR_LIT>' ] ( '<STR_LIT>' , <NUM_LIT> ) <EOL> if password is None : <EOL> password = __salt__ [ '<STR_LIT>' ] ( '<STR_LIT>' ) <EOL> return redis . StrictRedis ( host , port , password = password ) <EOL> def bgrewriteaof ( host = None , port = None , db = None , password = None ) : <EOL> '''<STR_LIT>''' <EOL> server = _connect ( host , port , db , password ) <EOL> return server . bgrewriteaof ( ) <EOL> def bgsave ( host = None , port = None , db = None , password = None ) : <EOL> '''<STR_LIT>''' <EOL> server = _connect ( host , port , db , password ) <EOL> return server . bgsave ( ) <EOL> def config_get ( pattern = '<STR_LIT:*>' , host = None , port = None , db = None , password = None ) : <EOL> '''<STR_LIT>''' <EOL> server = _connect ( host , port , db , password ) <EOL> return server . config_get ( pattern ) <EOL> def config_set ( name , value , host = None , port = None , db = None , password = None ) : <EOL> '''<STR_LIT>''' <EOL> server = _connect ( host , port , db , password ) <EOL> return server . config_set ( name , value ) <EOL> def dbsize ( host = None , port = None , db = None , password = None ) : <EOL> '''<STR_LIT>''' <EOL> server = _connect ( host , port , db , password ) <EOL> return server . dbsize ( ) <EOL> def delete ( * keys , ** connection_args ) : <EOL> '''<STR_LIT>''' <EOL> conn_args = { } <EOL> for arg in [ '<STR_LIT:host>' , '<STR_LIT:port>' , '<STR_LIT>' , '<STR_LIT:password>' ] : <EOL> if arg in connection_args : <EOL> conn_args [ arg ] = connection_args [ arg ] <EOL> server = _connect ( ** conn_args ) <EOL> return server . delete ( * keys ) <EOL> def exists ( key , host = None , port = None , db = None , password = None ) : <EOL> '''<STR_LIT>''' <EOL> server = _connect ( host , port , db , password ) <EOL> return server . exists ( key ) <EOL> def expire ( key , seconds , host = None , port = None , db = None , password = None ) : <EOL> '''<STR_LIT>''' <EOL> server = _connect ( host , port , db , password ) <EOL> return server . expire ( key , seconds ) <EOL> def expireat ( key , timestamp , host = None , port = None , db = None , password = None ) : <EOL> '''<STR_LIT>''' <EOL> server = _connect ( host , port , db , password ) <EOL> return server . expireat ( key , timestamp ) <EOL> def flushall ( host = None , port = None , db = None , password = None ) : <EOL> '''<STR_LIT>''' <EOL> server = _connect ( host , port , db , password ) <EOL> return server . flushall ( ) <EOL> def flushdb ( host = None , port = None , db = None , password = None ) : <EOL> '''<STR_LIT>''' <EOL> server = _connect ( host , port , db , password ) <EOL> return server . flushdb ( ) <EOL> def get_key ( key , host = None , port = None , db = None , password = None ) : <EOL> '''<STR_LIT>''' <EOL> server = _connect ( host , port , db , password ) <EOL> return server . get ( key ) <EOL> def hget ( key , field , host = None , port = None , db = None , password = None ) : <EOL> '''<STR_LIT>''' <EOL> server = _connect ( host , port , db , password ) <EOL> return server . hget ( key , field ) <EOL> def hgetall ( key , host = None , port = None , db = None , password = None ) : <EOL> '''<STR_LIT>''' <EOL> server = _connect ( host , port , db , password ) <EOL> return server . hgetall ( key ) <EOL> def info ( host = None , port = None , db = None , password = None ) : <EOL> '''<STR_LIT>''' <EOL> server = _connect ( host , port , db , password ) <EOL> return server . info ( ) <EOL> def keys ( pattern = '<STR_LIT:*>' , host = None , port = None , db = None , password = None ) : <EOL> '''<STR_LIT>''' <EOL> server = _connect ( host , port , db , password ) <EOL> return server . keys ( pattern ) <EOL> def key_type ( key , host = None , port = None , db = None , password = None ) : <EOL> '''<STR_LIT>''' <EOL> server = _connect ( host , port , db , password ) <EOL> return server . type ( key ) <EOL> def lastsave ( host = None , port = None , db = None , password = None ) : <EOL> '''<STR_LIT>''' <EOL> server = _connect ( host , port , db , password ) <EOL> return int ( server . lastsave ( ) . strftime ( "<STR_LIT:%s>" ) ) <EOL> def llen ( key , host = None , port = None , db = None , password = None ) : <EOL> '''<STR_LIT>''' <EOL> server = _connect ( host , port , db , password ) <EOL> return server . llen ( key ) <EOL> def lrange ( key , start , stop , host = None , port = None , db = None , password = None ) : <EOL> '''<STR_LIT>''' <EOL> server = _connect ( host , port , db , password ) <EOL> return server . lrange ( key , start , stop ) <EOL> def ping ( host = None , port = None , db = None , password = None ) : <EOL> '''<STR_LIT>''' <EOL> server = _connect ( host , port , db , password ) <EOL> try : <EOL> return server . ping ( ) <EOL> except redis . ConnectionError : <EOL> return False <EOL> def save ( host = None , port = None , db = None , password = None ) : <EOL> '''<STR_LIT>''' <EOL> server = _connect ( host , port , db , password ) <EOL> return server . save ( ) <EOL> def set_key ( key , value , host = None , port = None , db = None , password = None ) : <EOL> '''<STR_LIT>''' <EOL> server = _connect ( host , port , db , password ) <EOL> return server . set ( key , value ) <EOL> def shutdown ( host = None , port = None , db = None , password = None ) : <EOL> '''<STR_LIT>''' <EOL> server = _connect ( host , port , db , password ) <EOL> try : <EOL> server . ping ( ) <EOL> except redis . ConnectionError : <EOL> return False <EOL> server . shutdown ( ) <EOL> try : <EOL> server . ping ( ) <EOL> except redis . ConnectionError : <EOL> return True <EOL> return False <EOL> def slaveof ( master_host = None , master_port = None , host = None , port = None , db = None , <EOL> password = None ) : <EOL> '''<STR_LIT>''' <EOL> if master_host and not master_port : <EOL> master_port = <NUM_LIT> <EOL> server = _connect ( host , port , db , password ) <EOL> return server . slaveof ( master_host , master_port ) <EOL> def smembers ( key , host = None , port = None , db = None , password = None ) : <EOL> '''<STR_LIT>''' <EOL> server = _connect ( host , port , db , password ) <EOL> return list ( server . smembers ( key ) ) <EOL> def time ( host = None , port = None , db = None , password = None ) : <EOL> '''<STR_LIT>''' <EOL> server = _connect ( host , port , db , password ) <EOL> return server . time ( ) [ <NUM_LIT:0> ] <EOL> def zcard ( key , host = None , port = None , db = None , password = None ) : <EOL> '''<STR_LIT>''' <EOL> server = _connect ( host , port , db , password ) <EOL> return server . zcard ( key ) <EOL> def zrange ( key , start , stop , host = None , port = None , db = None , password = None ) : <EOL> '''<STR_LIT>''' <EOL> server = _connect ( host , port , db , password ) <EOL> return server . zrange ( key , start , stop ) <EOL> def sentinel_get_master_ip ( master , host = None , port = None , password = None ) : <EOL> '''<STR_LIT>''' <EOL> server = _sconnect ( host , port , password ) <EOL> ret = server . sentinel_get_master_addr_by_name ( master ) <EOL> return dict ( list ( zip ( ( '<STR_LIT>' , '<STR_LIT>' ) , ret ) ) ) <EOL> def get_master_ip ( host = None , port = None , password = None ) : <EOL> '''<STR_LIT>''' <EOL> server = _connect ( host , port , password ) <EOL> info = server . info ( ) <EOL> ret = ( info . get ( '<STR_LIT>' , '<STR_LIT>' ) , info . get ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> return dict ( list ( zip ( ( '<STR_LIT>' , '<STR_LIT>' ) , ret ) ) ) </s>
