<s> import redis <EOL> try : <EOL> from urllib . parse import urlparse <EOL> except ImportError : <EOL> from urlparse import urlparse <EOL> class Client ( object ) : <EOL> def __init__ ( self , conn_string ) : <EOL> """<STR_LIT>""" <EOL> self . conn_string = conn_string <EOL> bits = urlparse ( self . conn_string ) <EOL> self . conn = self . get_connection ( <EOL> host = bits . hostname , <EOL> port = bits . port , <EOL> db = bits . path . lstrip ( '<STR_LIT:/>' ) . split ( '<STR_LIT:/>' ) [ <NUM_LIT:0> ] <EOL> ) <EOL> def get_connection ( self , host , port , db ) : <EOL> """<STR_LIT>""" <EOL> return redis . StrictRedis ( <EOL> host = host , <EOL> port = port , <EOL> db = db , <EOL> decode_responses = True <EOL> ) <EOL> def len ( self , queue_name ) : <EOL> """<STR_LIT>""" <EOL> return self . conn . llen ( queue_name ) <EOL> def drop_all ( self , queue_name ) : <EOL> """<STR_LIT>""" <EOL> task_ids = self . conn . lrange ( queue_name , <NUM_LIT:0> , - <NUM_LIT:1> ) <EOL> for task_id in task_ids : <EOL> self . conn . delete ( task_id ) <EOL> self . conn . delete ( queue_name ) <EOL> def push ( self , queue_name , task_id , data ) : <EOL> """<STR_LIT>""" <EOL> self . conn . lpush ( queue_name , task_id ) <EOL> self . conn . set ( task_id , data ) <EOL> return task_id <EOL> def pop ( self , queue_name ) : <EOL> """<STR_LIT>""" <EOL> task_id = self . conn . lpop ( queue_name ) <EOL> data = self . conn . get ( task_id ) <EOL> self . conn . delete ( task_id ) <EOL> return data <EOL> def get ( self , queue_name , task_id ) : <EOL> """<STR_LIT>""" <EOL> self . conn . lrem ( queue_name , <NUM_LIT:1> , task_id ) <EOL> data = self . conn . get ( task_id ) <EOL> if data : <EOL> self . conn . delete ( task_id ) <EOL> return data </s>
