-
Notifications
You must be signed in to change notification settings - Fork 0
/
retriever.py
42 lines (33 loc) · 954 Bytes
/
retriever.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import asyncio
import logging
from random import randint
from db import Redis
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
redis = Redis()
async def playground(redis_: Redis):
# pylint: disable=global-statement
count, success, fail = 0, 0, 0
while True:
count += 1
key = f"foo-{randint(0, 10000)}"
try:
_ = await redis_.get(f"test:{key}")
success += 1
except Exception:
fail += 1
logger.error("[ERROR] get %s", key)
await asyncio.sleep(0.1)
if count % 100 == 0:
logger.info(
"[PROGRESS] %s success, %s fail -> rate %s",
success,
fail,
success / (success + fail),
)
async def main():
await redis.initialize()
await playground(redis)
await redis.destroy()
if __name__ == "__main__":
asyncio.run(main())