def get_following_user_id_set(cls, from_user_id): # cache set in Redis name = FOLLOWINGS_PATTERN.format(user_id=from_user_id) user_id_set = RedisHelper.get_all_members_from_set(name) # cache hit, need to change b'123' -> 123 if user_id_set is not None: user_id_set_new = set([]) for user_id in user_id_set: if isinstance(user_id, bytes): user_id = user_id.decode('utf-8') user_id_set_new.add(int(user_id)) return user_id_set_new # cache miss if not GateKeeper.is_switch_on('switch_friendship_to_hbase'): friendships = Friendship.objects.filter(from_user_id=from_user_id) else: friendships = HBaseFollowing.filter(prefix=(from_user_id, None)) user_id_set = set([ fs.to_user_id for fs in friendships ]) # push in Redis RedisHelper.add_id_to_set(name, user_id_set) return user_id_set
def add_following_id_in_redis(cls, from_user_id, to_user_id): name = FOLLOWINGS_PATTERN.format(user_id=from_user_id) id_set = set([to_user_id]) RedisHelper.add_id_to_set(name, id_set)