123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- # -*- coding: utf-8 -*-
- """
- Created on 2021-04-18 14:12:21
- ---------
- @summary: 导出数据(写入Redis,不直接保存在MongoDB)
- ---------
- @author: 马国鹏
- @email: 305021384@qq.com
- """
- from typing import Dict, List
- from feapder.db.redisdb import RedisDB
- from feapder.pipelines import BasePipeline
- from feapder.utils.tools import log
- class RedisPipeline(BasePipeline):
- def __init__(self):
- self._to_db = None
- @property
- def to_db(self):
- if not self._to_db:
- self._to_db = RedisDB()
- return self._to_db
- def save_items(self, table, items: List[Dict]) -> bool:
- """
- 保存数据
- Args:
- table: 表名
- items: 数据,[{},{},...]
- Returns: 是否保存成功 True / False
- 若False,不会将本批数据入到去重库,以便再次入库
- """
- try:
- self.to_db.lpush(table=table, values=items)
- datas_size = len(items)
- log.info("共导出 %s 条数据到 %s" % (datas_size, table))
- return True
- except Exception as e:
- log.exception(e)
- return False
|