|
|
@@ -67,17 +67,15 @@ class RedisClient(object):
|
|
|
:param proxy: proxy
|
|
|
:return: new score
|
|
|
"""
|
|
|
- score = self.db.zscore(REDIS_KEY, proxy.string())
|
|
|
- # current score is larger than PROXY_SCORE_MIN
|
|
|
- if score and score > PROXY_SCORE_MIN:
|
|
|
- logger.info(f'{proxy.string()} current score {score}, decrease 1')
|
|
|
- if IS_REDIS_VERSION_2:
|
|
|
- return self.db.zincrby(REDIS_KEY, proxy.string(), -1)
|
|
|
- return self.db.zincrby(REDIS_KEY, -1, proxy.string())
|
|
|
- # otherwise delete proxy
|
|
|
+ if IS_REDIS_VERSION_2:
|
|
|
+ self.db.zincrby(REDIS_KEY, proxy.string(), -1)
|
|
|
else:
|
|
|
+ self.db.zincrby(REDIS_KEY, -1, proxy.string())
|
|
|
+ score = self.db.zscore(REDIS_KEY, proxy.string())
|
|
|
+ logger.info(f'{proxy.string()} score decrease 1, current {score}')
|
|
|
+ if score <= PROXY_SCORE_MIN:
|
|
|
logger.info(f'{proxy.string()} current score {score}, remove')
|
|
|
- return self.db.zrem(REDIS_KEY, proxy.string())
|
|
|
+ self.db.zrem(REDIS_KEY, proxy.string())
|
|
|
|
|
|
def exists(self, proxy: Proxy) -> bool:
|
|
|
"""
|
|
|
@@ -112,17 +110,19 @@ class RedisClient(object):
|
|
|
"""
|
|
|
return convert_proxy_or_proxies(self.db.zrangebyscore(REDIS_KEY, PROXY_SCORE_MIN, PROXY_SCORE_MAX))
|
|
|
|
|
|
- def batch(self, start, end) -> List[Proxy]:
|
|
|
+ def batch(self, cursor, count) -> List[Proxy]:
|
|
|
"""
|
|
|
get batch of proxies
|
|
|
- :param start: start index
|
|
|
- :param end: end index
|
|
|
+ :param cursor: scan cursor
|
|
|
+ :param count: scan count
|
|
|
:return: list of proxies
|
|
|
"""
|
|
|
- return convert_proxy_or_proxies(self.db.zrevrange(REDIS_KEY, start, end - 1))
|
|
|
+ cursor, proxies = self.db.zscan(REDIS_KEY, cursor, count=count)
|
|
|
+ return cursor, convert_proxy_or_proxies([i[0] for i in proxies])
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
conn = RedisClient()
|
|
|
result = conn.random()
|
|
|
print(result)
|
|
|
+
|