# Path: lib/_db.py
# def get_collection(db_name, collection_name, client='mongo'):
# def get_db(db_name, client='mongo'):


from lib._db import redis_client as r
        else:
            r.zadd(self.domain_zset, self.incr_id.get(), url)

    def add_url_list(self, url_list, chunks=1000):
        for chunk_url_list in self.chunks(url_list, chunks):
            p = r.pipeline()
            for url in chunk_url_list:
                p.zadd(self.domain_zset, self.incr_id.get(), url)
            p.execute()

    def remove_url(self, url):
        r.sadd(self.remain_set, url)
        return r.zrem(self.domain_zset, url)

    def url_nums_has_crawler(self):
        return r.scard(self.remain_set)

    @staticmethod
    def chunks(l, n):
        """Yield successive n-sized chunks from l."""
        for i in range(0, len(l), n):
            yield l[i:i+n]

    def url_nums(self):
        return r.zcard(self.domain_zset)

    def has_url(self, url):
        return bool(r.zscore(self.domain_zset, url))

    def first_url(self):

# Path: lib/_db.py
# def get_collection(db_name, collection_name, client='mongo'):
# def get_db(db_name, client='mongo'):


# Path: crawler/lagou/utils.py
from lib._db import redis_client as r

        else:
            r.zadd(self.domain_zset, self.incr_id.get(), url)

    def add_url_list(self, url_list, chunks=1000):
        for chunk_url_list in self.chunks(url_list, chunks):
            p = r.pipeline()
            for url in chunk_url_list:
                p.zadd(self.domain_zset, self.incr_id.get(), url)
            p.execute()

    def remove_url(self, url):
        r.sadd(self.remain_set, url)
        return r.zrem(self.domain_zset, url)

    def url_nums_has_crawler(self):
        return r.scard(self.remain_set)

    @staticmethod
    def chunks(l, n):
        """Yield successive n-sized chunks from l."""
        for i in range(0, len(l), n):
            yield l[i:i+n]

    def url_nums(self):
        return r.zcard(self.domain_zset)

    def has_url(self, url):
        return bool(r.zscore(self.domain_zset, url))

    def first_url(self):

        rl = r.zrange(self.domain_zset, 0, 0)    # min score