Ejemplo n.º 1
0
 def __init_uid_info(self, redis_conn):
     """
     初始化用户ID
     :param redis_conn:
     :return:
     """
     db_relation = self._get_incidence_relation("USER_ID")
     mongodb_table = db_relation.get("MONGODB")
     redis_table = db_relation.get("REDIS")
     redis_uid_list_table = db_relation.get("REDIS_UID_LIST")
     mongodb_conn = self.__get_mongodb_conn(table_name=mongodb_table)
     query = {}
     projection = {"uid": 1, "_id": 0}
     user_infos = mongodb_conn.select(query=query,
                                      projection=projection,
                                      to_list=False)
     with redis_conn.pipeline() as rpipe:
         for user in user_infos:
             key = user.get("uid")
             rpipe.hset(redis_table, key, get_timestamp())
             rpipe.lpush(redis_uid_list_table, key)  # uid 队列
         rpipe.execute()
         uid_count = redis_conn.hlen(redis_table)
         self.logger.info("--->成功初始化用户UID数据条数为:%d" % uid_count)
         return True
Ejemplo n.º 2
0
 def add_key(self, table_type, key, value=None):
     """
     添加新key
     :param table_type:
     :param key:
     :param value:
     :return:
     """
     table_name = self.__get_table_name(table_type=table_type)
     if self.__is_key_exist(table_name=table_name, key=key):
         self.logger.info("表%s中已经存在该key:%s" % (table_name, key))
         value = self.__get_key_value(table_name, key)
     else:
         self.__get_redis_conn()
         if value is None:
             value = get_timestamp()
         self.redis.hset(table_name, key, value)
         self.logger.info("向表%s中添加key%s成功 ---> %s" %
                          (table_name, key, value))
     return value
Ejemplo n.º 3
0
 def __init_bid_info(self, redis_conn):
     """
     初始化微博ID
     :param redis_conn:
     :return:
     """
     db_relation = self._get_incidence_relation("BLOG_ID")
     mongodb_table = db_relation.get("MONGODB")
     redis_table = db_relation.get("REDIS")
     mongodb_conn = self.__get_mongodb_conn(table_name=mongodb_table)
     query = {}
     projection = {"uid": 1, "bid": 1, "_id": 0}
     blog_infos = mongodb_conn.select(query=query,
                                      projection=projection,
                                      to_list=False)
     with redis_conn.pipeline() as rpipe:
         for blog in blog_infos:
             key = "%s_%s" % (blog.get("uid"), blog.get("bid"))
             rpipe.hset(redis_table, key, get_timestamp())
         rpipe.execute()
         bid_count = redis_conn.hlen(redis_table)
         self.logger.info("--->成功初始化微博BID数据条数为:%d" % bid_count)
         return True
Ejemplo n.º 4
0
 def __init_folid_info(self, redis_conn):
     """
     初始化关注人ID
     :param redis_conn:
     :return:
     """
     db_relation = self._get_incidence_relation("FOLLOW_ID")
     mongodb_table = db_relation.get("MONGODB")
     redis_table = db_relation.get("REDIS")
     mongodb_conn = self.__get_mongodb_conn(table_name=mongodb_table)
     query = {}
     projection = {"uid": 1, "folid": 1, "_id": 0}
     follow_infos = mongodb_conn.select(query=query,
                                        projection=projection,
                                        to_list=False)
     with redis_conn.pipeline() as rpipe:
         for follow in follow_infos:
             key = "%s_%s" % (follow.get("uid"), follow.get("folid"))
             rpipe.hset(redis_table, key, get_timestamp())
         rpipe.execute()
         folid_count = redis_conn.hlen(redis_table)
         self.logger.info("--->成功初始化关注人FOLID数据条数为:%d" % folid_count)
         return True