<s> class UserFollowGraph ( object ) : <EOL> def __init__ ( self , client ) : <EOL> self . client = client <EOL> self . FOLLOWS_KEY = '<STR_LIT:F>' <EOL> self . FOLLOWERS_KEY = '<STR_LIT:f>' <EOL> self . BLOCKS_KEY = '<STR_LIT:B>' <EOL> self . BLOCKED_KEY = '<STR_LIT:b>' <EOL> def follow ( self , from_user , to_user ) : <EOL> if to_user in self . get_follows ( from_user ) : <EOL> return False <EOL> forward_key = '<STR_LIT>' % ( self . FOLLOWS_KEY , from_user ) <EOL> forward = self . client . lpush ( forward_key , to_user ) <EOL> reverse_key = '<STR_LIT>' % ( self . FOLLOWERS_KEY , to_user ) <EOL> reverse = self . client . lpush ( reverse_key , from_user ) <EOL> return forward and reverse <EOL> def unfollow ( self , from_user , to_user ) : <EOL> if to_user not in self . get_follows ( from_user ) : <EOL> return False <EOL> forward_key = '<STR_LIT>' % ( self . FOLLOWS_KEY , from_user ) <EOL> forward = self . client . lrem ( forward_key , <NUM_LIT:0> , to_user ) <EOL> reverse_key = '<STR_LIT>' % ( self . FOLLOWERS_KEY , to_user ) <EOL> reverse = self . client . lrem ( reverse_key , <NUM_LIT:0> , from_user ) <EOL> return forward and reverse <EOL> def get_follows ( self , user ) : <EOL> return list ( self . client . lrange ( '<STR_LIT>' % ( self . FOLLOWS_KEY , user ) , <NUM_LIT:0> , - <NUM_LIT:1> ) ) <EOL> def get_followers ( self , user ) : <EOL> return list ( self . client . lrange ( '<STR_LIT>' % ( self . FOLLOWERS_KEY , user ) , <NUM_LIT:0> , - <NUM_LIT:1> ) ) <EOL> def is_follow ( self , user_a , user_b ) : <EOL> return str ( user_b ) in self . get_follows ( user_a ) <EOL> def is_follower ( self , user_a , user_b ) : <EOL> return str ( user_b ) in self . get_followers ( user_a ) <EOL> def is_mutual ( self , user_a , user_b ) : <EOL> return self . is_follow ( user_a , user_b ) and self . is_follower ( user_a , user_b ) <EOL> def follow_count ( self , user ) : <EOL> return self . client . llen ( '<STR_LIT>' % ( self . FOLLOWS_KEY , user ) ) <EOL> def follower_count ( self , user ) : <EOL> return self . client . llen ( '<STR_LIT>' % ( self . FOLLOWERS_KEY , user ) ) <EOL> def common_follow ( self , user_a , user_b ) : <EOL> follows_a = self . get_follows ( user_a ) <EOL> follows_b = self . get_follows ( user_b ) <EOL> return list ( set ( follows_a ) . intersection ( set ( follows_b ) ) ) <EOL> def common_follower ( self , user_a , user_b ) : <EOL> followers_a = self . get_followers ( user_a ) <EOL> followers_b = self . get_followers ( user_b ) <EOL> return list ( set ( followers_a ) . intersection ( set ( followers_b ) ) ) </s>
