From a979dc04d292280cd24f656d2e9ffb8e6d465bf2 Mon Sep 17 00:00:00 2001 From: liaozetao <1107136310@qq.com> Date: Wed, 18 Oct 2023 11:08:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=A4=BA=E5=AE=9Dredis?= =?UTF-8?q?=E6=B8=85=E7=90=86=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- python/peko_seize_treasure_user_info.py | 53 +++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 python/peko_seize_treasure_user_info.py diff --git a/python/peko_seize_treasure_user_info.py b/python/peko_seize_treasure_user_info.py new file mode 100644 index 000000000..3194bc565 --- /dev/null +++ b/python/peko_seize_treasure_user_info.py @@ -0,0 +1,53 @@ +# pip3 install redis + +import redis +import json +from concurrent.futures import ThreadPoolExecutor + +res = None + + +def connect(): + res = redis.StrictRedis(host='172.22.0.8', port=6379, db=0, password='pc8DphhaXwTe2jyv') + return res + + +def scan(): + # 创建一个包含100条线程的线程池 + thread = ThreadPoolExecutor(max_workers=100) + cursor = 0 + while True: + tup = res.scan(cursor=cursor, match='peko:seize_treasure:user_info:*', count=1000) + k = tup[0] + v = tup[1] + if isinstance(k, int): + cursor = k + if isinstance(v, list): + # 启动线程执行 + try: + handle_keys(v) + except Exception as e: + print("thread submit error.", e) + if cursor == 0: + break + # 关闭线程池 + thread.shutdown() + + +def handle_keys(keys): + try: + for k in keys: + key = k.decode('utf-8') + print(key) + # res.delete(key) + except Exception as e: + print("handle_keys error.", e) + + +if __name__ == '__main__': + res = connect() + if res is None: + print("redis connect is error.") + else: + print("redis connect is success.") + scan()