MCPcopy Index your code
hub / github.com/Python3WebSpider/ProxyPool / randoms

Method randoms

proxypool/storages/redis.py:73–92  ·  view source on GitHub ↗

get a batch of random proxies firstly try to get proxies with max score, if not enough, get proxies by rank (score from high to low) if none exists, raise error :param count: number of proxies to return :return: list of proxies

(self, count, redis_key=REDIS_KEY, proxy_score_min=PROXY_SCORE_MIN, proxy_score_max=PROXY_SCORE_MAX)

Source from the content-addressed store, hash-verified

71 raise PoolEmptyException
72
73 def randoms(self, count, redis_key=REDIS_KEY, proxy_score_min=PROXY_SCORE_MIN, proxy_score_max=PROXY_SCORE_MAX) -> List[Proxy]:
74 """
75 get a batch of random proxies
76 firstly try to get proxies with max score,
77 if not enough, get proxies by rank (score from high to low)
78 if none exists, raise error
79 :param count: number of proxies to return
80 :return: list of proxies
81 """
82 # try to get proxies with max score first
83 proxies = self.db.zrangebyscore(
84 redis_key, proxy_score_max, proxy_score_max)
85 if len(proxies) < count:
86 # not enough max-score proxies, fall back to all proxies by rank
87 proxies = self.db.zrevrangebyscore(
88 redis_key, proxy_score_max, proxy_score_min)
89 if not proxies:
90 raise PoolEmptyException
91 count = min(count, len(proxies))
92 return convert_proxy_or_proxies(sample(proxies, count))
93
94 def decrease(self, proxy: Proxy, redis_key=REDIS_KEY, proxy_score_min=PROXY_SCORE_MIN) -> int:
95 """

Callers 1

get_proxyFunction · 0.80

Calls 1

convert_proxy_or_proxiesFunction · 0.90

Tested by

no test coverage detected